| Home | Libraries | People | FAQ | More

## Class template small_vector

boost::container::small_vector

## Synopsis

    // In header: <boost/container/small_vector.hpp>

    template<typename T, std::size_t N, typename Allocator = void,
             typename Options = void>
    class small_vector :
      public boost::container::small_vector_base< T, Allocator, Options >
    {
    public:
      // construct/copy/destruct
      small_vector() noexcept(dtl::is_nothrow_default_constructible< allocator_type >::value));
      explicit small_vector(const allocator_type &);
      explicit small_vector(size_type);
      small_vector(size_type, const allocator_type &);
      small_vector(size_type, default_init_t);
      small_vector(size_type, default_init_t, const allocator_type &);
      small_vector(size_type, const value_type &);
      small_vector(size_type, const value_type &, const allocator_type &);
      template<typename InIt> small_vector(InIt, InIt last );
      template<typename InIt> small_vector(InIt, InIt, const allocator_type &a );
      small_vector(const small_vector &);
      small_vector(const small_vector &, const allocator_type &);
      explicit small_vector(const base_type &);
      explicit small_vector(base_type &&);
      small_vector(small_vector &&) noexcept(boost::container::dtl::is_nothrow_move_assignable< value_type >::value));
      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 &&) noexcept(boost::container::dtl::is_nothrow_move_assignable< value_type >::value &&(allocator_traits_type::propagate_on_container_move_assignment::value||allocator_traits_type::is_always_equal::value)));
      small_vector & operator=(const base_type &);
      small_vector & operator=(base_type &&);

      // public member functions
      void swap(small_vector &);
    };

## Description

small_vector is a vector-like container optimized for the case when it contains few elements. It contains some preallocated elements in-place, which can avoid the use of dynamic storage allocation when the actual number of elements is below that preallocated threshold.

`small_vector<T, N, Allocator, Options>` is convertible to `small_vector_base<T, Allocator, Options>` 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.

### Template Parameters

1.     typename T

   The type of object that is stored in the `small_vector`

2.     std::size_t N

   The number of preallocated elements stored inside `small_vector`. It shall be less than Allocator::max_size();

3.     typename Allocator = void

   The allocator used for memory management when the number of elements exceeds N. Use void for the default allocator |tparam Options A type produced from ``boost::container::small_vector_options``.

4.     typename Options = void

### `small_vector` public construct/copy/destruct

1.     small_vector() noexcept(dtl::is_nothrow_default_constructible< allocator_type >::value));

2.     explicit small_vector(const allocator_type & a);

3.     explicit small_vector(size_type n);

4.     small_vector(size_type n, const allocator_type & a);

5.     small_vector(size_type n, default_init_t);

6.     small_vector(size_type n, default_init_t, const allocator_type & a);

7.     small_vector(size_type n, const value_type & v);

8.     small_vector(size_type n, const value_type & v, const allocator_type & a);

9.     template<typename InIt>
         small_vector(InIt first, InIt last  BOOST_CONTAINER_DOCIGN);

10.     template<typename InIt>
          small_vector(InIt first, InIt last,
                       const allocator_type &a  BOOST_CONTAINER_DOCIGN);

11.     small_vector(const small_vector & other);

12.     small_vector(const small_vector & other, const allocator_type & a);

13.     explicit small_vector(const base_type & other);

14.     explicit small_vector(base_type && other);

15.     small_vector(small_vector && other) noexcept(boost::container::dtl::is_nothrow_move_assignable< value_type >::value));

16.     small_vector(small_vector && other, const allocator_type & a);

17.     small_vector(std::initializer_list< value_type > il,
                     const allocator_type & a = allocator_type());

18.     small_vector & operator=(const small_vector & other);

19.     small_vector &
        operator=(small_vector && other) noexcept(boost::container::dtl::is_nothrow_move_assignable< value_type >::value &&(allocator_traits_type::propagate_on_container_move_assignment::value||allocator_traits_type::is_always_equal::value)));

20.     small_vector & operator=(const base_type & other);

21.     small_vector & operator=(base_type && other);

### `small_vector` public member functions

1.     void swap(small_vector & other);