...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_base
// In header: <boost/container/small_vector.hpp> template<typename T, typename SecAlloc, typename Options> class small_vector_base : public boost::container::vector< T, A, Options > { public: // types typedef real_allocator< T, SecAlloc >::type underlying_allocator_t; typedef allocator_traits< underlying_allocator_t >::template portable_rebind_alloc< void >::type void_underlying_allocator_t; typedef small_vector_allocator< T, void_underlying_allocator_t, Options > allocator_type; typedef dtl::get_small_vector_opt< Options >::type options_t; typedef dtl::vector_for_small_vector< T, SecAlloc, Options >::type base_type; typedef allocator_traits< allocator_type >::pointer pointer; typedef allocator_traits< allocator_type >::const_pointer const_pointer; typedef allocator_traits< allocator_type >::void_pointer void_pointer; typedef allocator_traits< allocator_type >::const_void_pointer const_void_pointer; typedef base_type::size_type size_type; // private member functions const_pointer internal_storage() const noexcept; pointer internal_storage() noexcept; base_type & as_base(); const base_type & as_base() const; // public member functions bool is_small() const; small_vector_base & operator=(const small_vector_base &); small_vector_base & operator=(small_vector_base &&); void swap(small_vector_base &); // protected member functions explicit small_vector_base(initial_capacity_t, size_type); template<typename AllocFwd> explicit small_vector_base(initial_capacity_t, size_type, AllocFwd &&); template<typename AllocFwd> explicit small_vector_base(initial_capacity_t, size_type, AllocFwd &&, small_vector_base &); explicit small_vector_base(maybe_initial_capacity_t, size_type, size_type); template<typename AllocFwd> explicit small_vector_base(maybe_initial_capacity_t, size_type, size_type, AllocFwd &&); void prot_shrink_to_fit_small(const size_type); void prot_swap(small_vector_base &, size_type); };
This class consists of common code from all small_vector<T, N> types that don't depend on the "N" template parameter. This class is non-copyable and non-destructible, so this class typically used as reference argument to functions that read or write small vectors. Since small_vector<T, N>
derives from small_vector_base<T>
, the conversion to small_vector_base
is implicit
//Clients can pass any small_vector<Foo, N>. void read_any_small_vector_of_foo(const small_vector_base<Foo> &in_parameter); void modify_any_small_vector_of_foo(small_vector_base<Foo> &in_out_parameter); void some_function() { small_vector<Foo, 8> myvector; read_any_small_vector_of_foo(myvector); // Reads myvector modify_any_small_vector_of_foo(myvector); // Modifies myvector }
All boost::container:vector
member functions are inherited. See vector
documentation for details.
small_vector_base
public member functionsbool is_small() const;
small_vector_base & operator=(const small_vector_base & other);
small_vector_base & operator=(small_vector_base && other);
void swap(small_vector_base & other);
small_vector_base
protected member functionsexplicit small_vector_base(initial_capacity_t, size_type initial_capacity);
template<typename AllocFwd> explicit small_vector_base(initial_capacity_t, size_type capacity, AllocFwd && a);
template<typename AllocFwd> explicit small_vector_base(initial_capacity_t, size_type capacity, AllocFwd && a, small_vector_base & x);
explicit small_vector_base(maybe_initial_capacity_t, size_type initial_capacity, size_type initial_size);
template<typename AllocFwd> explicit small_vector_base(maybe_initial_capacity_t, size_type initial_capacity, size_type initial_size, AllocFwd && a);
void prot_shrink_to_fit_small(const size_type small_capacity);
void prot_swap(small_vector_base & other, size_type internal_capacity_value);