问题描述
我想知道我的同事今天是否std :: vector可以实现使用小缓冲区优化。通过查看C ++ 11草稿,我在23.3.1p8阅读
I was wondering with my colleague today whether std::vector can be implemented to make use of small buffer optimization. By looking into the C++11 draft, I read at 23.3.1p8
这首先似乎违反了小缓冲区优化,但是在as-if规则下,我们仍然可以做小缓冲区非类类型的优化(因为我们不能观察到拷贝)。下一个文本似乎更难以傻瓜
That at first seems to outlaw small buffer optimization, but under the as-if rule, we would be allowed to still do small buffer optimization for non-class types (since we cannot observe the copy being done). The next text appears to be harder to "fool"
这是否足以阻止对std :: vector实现小缓冲区优化?是否还有其他路障或者最终可能有一个带有SBO的std :: vector?
Is this sufficient to prevent implementing the small buffer optimization for std::vector? Are there any other road-blocks or is it eventually possible to have a std::vector with SBO?
推荐答案
/ p10 / b6:
23.2.1 / p10 / b6:
- 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:
- ^ 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()
这篇关于May std :: vector使用小缓冲区优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!