boost::container::vector和std::vector之间有什么区别?
答案 0 :(得分:11)
当您遇到struct sockaddr
专业化时,您可能需要升级版本而不是标准版本。
<bool>
是作为bitset实现的,它不会将其元素存储为std::vector<bool>
的数组。
这意味着例如以下代码将不起作用:
bool
template<T>
void handleElement(T &element);
// suppose we get a bool vector:
std::vector<bool> v = ....;
// then this fails because v[i] is a proxy object
handleElement(v[0]);
没有这样的专业化。
答案 1 :(得分:5)
我可以编译几个不同之处:
°boost::container::vector<bool>
没有专业化(来源@roeland)
decltype(std::vector<bool>(10)[0]) == std::_Bit_reference
decltype(boost::container::vector<bool>(10)[0]) == bool&
°使用Boost分配器基础结构,它(特别是在C ++ 1x中)比标准分配器更灵活,不会忽略分配器提供的某些特性。 (来源:http://www.boost.org/doc/libs/1_59_0/doc/html/interprocess/allocators_containers.html#interprocess.allocators_containers.containers_explained.stl_container_requirements)
std::vector<double>::allocator_type == std::allocator<double>
boost::container::vector<double>::alloctor_type == boost::container::new_allocator<double>
特别是,您仍然可以指定reference
和pointer
类型与T&
和T*
不同(请参阅Is it still possible to customize STL vector's "reference" type?)
°支持递归容器(来源:BorisSchäling的Boost C ++库)。
STL的一些(旧的?)实现不支持不完整的值类型(首先不需要它们),特别是递归容器。
using boost::container::vector;
struct animal{
vector<animal> children; // may not work with std::vector
};
int main(){
animal parent;
animal child1;
animal child2;
parent.children.push_back(child1);
parent.children.push_back(child2);
}
°std::vector
是规范而不是实现。
所有平台上只有一个实现boost::container::vector
,因此可以做出更多假设(例如,最初std::vector
不需要使用连续内存)(来源:BorisSchäling的Boost C ++库)。 / p>