...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::container::small_vector
// In header: <boost/container/small_vector.hpp> template<typename T, std::size_t N, typename Allocator = new_allocator<T> > class small_vector : public boost::container::small_vector_base< T, Allocator > { public: // construct/copy/destruct small_vector(); explicit small_vector(size_type); explicit small_vector(const allocator_type &); small_vector(size_type, const allocator_type &); small_vector(const small_vector &); small_vector(const small_vector &, const allocator_type &); small_vector(small_vector &&); small_vector(small_vector &&, const allocator_type &); small_vector(std::initializer_list< value_type >, const allocator_type & = allocator_type()); small_vector & operator=(const small_vector &); small_vector & operator=(small_vector &&); // public member functions void swap(small_vector &); };
small_vector a vector-like container optimized for the case when it contains few elements. It contains some preallocated elements in-place, which allows it to avoid the use of dynamic storage allocation when the actual number of elements is below that preallocated threshold.
small_vector<T, N, Allocator>
is convertible to small_vector_base<T, Allocator>
that is independent from the preallocated element capacity, so client code does not need to be templated on that N argument.
All boost::container::vector
member functions are inherited. See vector
documentation for details.
typename T
The type of object that is stored in the small_vector
std::size_t N
The number of preallocated elements stored inside small_vector
. It shall be less than Allocator::max_size();
typename Allocator = new_allocator<T>
The allocator used for memory management when the number of elements exceeds N.
small_vector
public
construct/copy/destructsmall_vector();
explicit small_vector(size_type n);
explicit small_vector(const allocator_type & a);
small_vector(size_type n, const allocator_type & a);
small_vector(const small_vector & other);
small_vector(const small_vector & other, const allocator_type & a);
small_vector(small_vector && other);
small_vector(small_vector && other, const allocator_type & a);
small_vector(std::initializer_list< value_type > il, const allocator_type & a = allocator_type());
small_vector & operator=(const small_vector & other);
small_vector & operator=(small_vector && other);