boost container

Boost Container provides additional advantages:

(1) The interface of the containers resemble those of the containers in the C++11 standard library.

(2) With boost::container::slist or boost::container::stable_vector, Boost container offers containers the standard library doesn't provide.

(3) The implementation is platform independent.

(4) The containers from Boost Container support incomplete types and can be used to define recursive containers.

#include <boost/container/stable_vector.hpp>
#include <iostream>

using namespace boost::container;

int main() {
  stable_vector<int> v(2, 1);
  int& i = v[1];
  v.erase(v.begin());
  std::cout << i << std::endl;
  return 0;
}

输出:1

boost::container::stable_vector behaves similarly to std::vector, except that if boost::container::stable_vector is changed, all iterators and references to existing elements remain valid. This is possible because elements aren't stored contiguously in boost::container::stable_vector. It is still possible to access elements with an index even though elements are not stored next to each other in memory.

 

Additional containers provided by Boost Container are boost::container::flat_set, boost::container::flat_map, boost::container_slist, boost::container::static_vector.

boost::container::static_vector stores elements like std::array directly in the container. Like std::array, the container has a constant capacity. The capacity is conastant, but can be changed with resize(). push_back() doesn't change the capacity, throws an exception of type std::bad_alloc.

转载于:https://www.cnblogs.com/sssblog/p/11051750.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值