且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

May std :: vector使用小缓冲区优化?

更新时间:2023-11-12 22:35:16

/ p10 / b6:

23.2.1 / p10 / b6:


除非另有规定...

Unless otherwise specified ...


  • no swap()函数使任何引用,指针或迭代器引用要交换的容器的元素无效。
    ...

c> vector 。所以这违反了SBO 向量

Nowhere does it "specify otherwise" for vector. So this outlaws the SBO for vector.

string 不受此规则约束,因为它在21.4.1 / p6中有指定:

string is not bound by this rule because it does "specify otherwise" in 21.4.1/p6:


引用,指针和迭代器
basic_string序列的元素可能由于以下对
basic_string对象的使用而失效:

References, pointers, and iterators referring to the elements of a basic_string sequence may be invalidated by the following uses of that basic_string object:


  • ^ 234

234)例如,作为一个参数,引用非const basic_string作为参数。非成员函数的参数swap()
(21.4.8.8),运算符>>()(21.4.8.9)和getline()(21.4.8.9),或者作为
参数basic_string :: swap()

234) For example, as an argument to non-member functions swap() (21.4.8.8), operator>>() (21.4.8.9), and getline() (21.4.8.9), or as an argument to basic_string::swap()