Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template static_vector

boost::container::static_vector — A variable-size array container with fixed capacity.

Synopsis

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

template<typename T,  Capacity, typename Options = void> 
class static_vector : public  {
public:
  // types
  typedef              ;              // The type of elements stored in the container. 
  typedef               ;               // The unsigned integral type used by the container. 
  typedef         ;         // The pointers difference type. 
  typedef                 ;                 // The pointer type. 
  typedef           ;           // The const pointer type. 
  typedef               ;               // The value reference type. 
  typedef         ;         // The value const reference type. 
  typedef                ;                // The iterator type. 
  typedef          ;          // The const iterator type. 
  typedef        ;        // The reverse iterator type. 
  typedef  ;  // The const reverse iterator. 

  // construct/copy/destruct
  () ;
  ();
  (, default_init_t);
  (, const &);
  template<typename Iterator> (Iterator, Iterator);
  ();
  (static_vector const &);
  (static_vector const &, const allocator_type &);
  (static_vector &&, const allocator_type &) ;
  (const allocator_type &);
  template< C, typename O> 
    (static_vector< T, C, O > const &);
  (static_vector &&) ;
  template< C, typename O> 
    (static_vector< T, C, O > &&);
  static_vector & (const static_vector &);
  static_vector & ();
  template< C, typename O> 
    static_vector & (static_vector< T, C, O > const &);
  static_vector & 
  (static_vector &&) ;
  template< C, typename O> 
    static_vector & (static_vector< T, C, O > &&);
  ~();

  // public member functions
  void (static_vector &);
  template< C, typename O> void (static_vector< T, C, O > &);
  void ();
  void (, default_init_t);
  void (, const &);
  void ();
  void (const &);
  void ();
  void () ;
   (, const &);
   (, );
   (, , const &);
  template<typename Iterator> 
     (, Iterator, Iterator);
   (, );
   ();
   (, );
  template<typename Iterator> void (Iterator, Iterator);
  void ();
  void (, const &);
  template< Args>  (Args &&...);
  template< Args>  (, Args &&...);
  void () ;
   ();
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
  T * () ;
  const T * () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
   () ;
  bool () ;

  // public static functions
   () ;
   () ;

  // public data members
  static const  static_capacity;  // The capacity/max size of the container. 
};

Description

static_vector is a sequence container like boost::container::vector with contiguous storage that can change in size, along with the static allocation, low overhead, and fixed capacity of boost::array.

A static_vector is a sequence that supports random access to elements, constant time insertion and removal of elements at the end, and linear time insertion and removal of elements at the beginning or in the middle. The number of elements in a static_vector may vary dynamically up to a fixed capacity because elements are stored within the object itself similarly to an array. However, objects are initialized as they are inserted into static_vector unlike C arrays or std::array which must construct all elements on instantiation. The behavior of static_vector enables the use of statically allocated elements in cases with complex object lifetime requirements that would otherwise not be trivially possible.

Error Handling. If throw_on_overflow option is true (default behaviour), insertion beyond the capacity result in throwing bad_alloc() if exceptions are enabled and or calling throw_bad_alloc() if not enabled. If throw_on_overflow option is false, insertion beyond capacity results in Undefined Behaviour.

out_of_range is thrown if out of bounds access is performed in at() if exceptions are enabled, throw_out_of_range() if not enabled.

Template Parameters

  1. typename T

    The type of element that will be stored.

  2.  Capacity

    The maximum number of elements static_vector can store, fixed at compile time.

  3. typename Options = void

    A type produced from boost::container::static_vector_options. If no option is specified, by default throw_on_overflow<true> option is set.

static_vector public construct/copy/destruct

  1. () ;
    Constructs an empty static_vector.

    Throws. Nothing.

    Complexity. Constant O(1).

  2. ( count);
    Constructs a static_vector containing count value initialized values.

    Throws. 

    • If T's value initialization throws

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    count

    The number of values which will be contained in the container.

    Requires:

    count <= capacity()

  3. ( count, default_init_t);
    Constructs a static_vector containing count default initialized values.

    Throws. 

    • If T's default initialization throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Note. Non-standard extension

    Parameters:

    count

    The number of values which will be contained in the container.

    Requires:

    count <= capacity()

  4. ( count, const & value);
    Constructs a static_vector containing count copies of value.

    Throws. 

    • If T's copy constructor throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    count

    The number of copies of a values that will be contained in the container.

    value

    The value which will be used to copy construct values.

    Requires:

    count <= capacity()

  5. template<typename Iterator> (Iterator first, Iterator last);
    Constructs a static_vector containing copy of a range [first, last).

    Throws. 

    • If T's constructor taking a dereferenced Iterator throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    first

    The iterator to the first element in range.

    last

    The iterator to the one after the last element in range.

    Requires:

    • distance(first, last) <= capacity()

    • Iterator must meet the ForwardTraversalIterator concept.

  6. ( il);
    Constructs a static_vector containing copy of a range [il.begin(), il.end()).

    Throws. 

    • If T's constructor taking a dereferenced std::initializer_list throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    il

    std::initializer_list with values to initialize vector.

    Requires:

    • distance(il.begin(), il.end()) <= capacity()

  7. (static_vector const & other);
    Constructs a copy of other static_vector.

    Throws. If T's copy constructor throws.

    Complexity. Linear O(N).

    Parameters:

    other

    The static_vector which content will be copied to this one.

  8. (static_vector const & other, const allocator_type &);
  9. (static_vector && other, const allocator_type &) ;
  10. (const allocator_type &);
  11. template< C, typename O> 
      (static_vector< T, C, O > const & other);
    Constructs a copy of other static_vector.

    Throws. 

    • If T's copy constructor throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    other

    The static_vector which content will be copied to this one.

    Requires:

    other.size() <= capacity().

  12. (static_vector && other) ;
    Move constructor. Moves Values stored in the other static_vector to this one.

    Throws. 

    • If has_nothrow_move<T>::value is true and T's move constructor throws.

    • If has_nothrow_move<T>::value is false and T's copy constructor throws.

    Complexity. Linear O(N).

    Parameters:

    other

    The static_vector which content will be moved to this one.

  13. template< C, typename O> 
      (static_vector< T, C, O > && other);
    Move constructor. Moves Values stored in the other static_vector to this one.

    Throws. 

    • If has_nothrow_move<T>::value is true and T's move constructor throws.

    • If has_nothrow_move<T>::value is false and T's copy constructor throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    other

    The static_vector which content will be moved to this one.

    Requires:

    other.size() <= capacity()

  14. static_vector & (const static_vector & other);
    Copy assigns Values stored in the other static_vector to this one.

    Throws. If T's copy constructor or copy assignment throws.

    Complexity. Linear O(N).

    Parameters:

    other

    The static_vector which content will be copied to this one.

  15. static_vector & ( il);
    Copy assigns Values stored in std::initializer_list to *this.

    Throws. 

    • If T's copy constructor or copy assignment throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    il

    The std::initializer_list which content will be copied to this one.

  16. template< C, typename O> 
      static_vector & (static_vector< T, C, O > const & other);
    Copy assigns Values stored in the other static_vector to this one.

    Throws. 

    • If T's copy constructor or copy assignment throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    other

    The static_vector which content will be copied to this one.

    Requires:

    other.size() <= capacity()

  17. static_vector & 
    (static_vector && other) ;
    Move assignment. Moves Values stored in the other static_vector to this one.

    Throws. 

    • If has_nothrow_move<T>::value is true and T's move constructor or move assignment throws.

    • If has_nothrow_move<T>::value is false and T's copy constructor or copy assignment throws.

    Complexity. Linear O(N).

    Parameters:

    other

    The static_vector which content will be moved to this one.

  18. template< C, typename O> 
      static_vector & (static_vector< T, C, O > && other);
    Move assignment. Moves Values stored in the other static_vector to this one.

    Throws. 

    • If has_nothrow_move<T>::value is true and T's move constructor or move assignment throws.

    • If has_nothrow_move<T>::value is false and T's copy constructor or copy assignment throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    other

    The static_vector which content will be moved to this one.

    Requires:

    other.size() <= capacity()

  19. ~();
    Destructor. Destroys Values stored in this container.

    Throws. Nothing

    Complexity. Linear O(N).

static_vector public member functions

  1. void (static_vector & other);
    Swaps contents of the other static_vector and this one.

    Throws. 

    • If has_nothrow_move<T>::value is true and T's move constructor or move assignment throws,

    • If has_nothrow_move<T>::value is false and T's copy constructor or copy assignment throws,

    Complexity. Linear O(N).

    Parameters:

    other

    The static_vector which content will be swapped with this one's content.

  2. template< C, typename O> 
      void (static_vector< T, C, O > & other);
    Swaps contents of the other static_vector and this one.

    Throws. 

    • If has_nothrow_move<T>::value is true and T's move constructor or move assignment throws,

    • If has_nothrow_move<T>::value is false and T's copy constructor or copy assignment throws,

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    other

    The static_vector which content will be swapped with this one's content.

    Requires:

    other.size() <= capacity() && size() <= other.capacity()

  3. void ( count);
    Inserts or erases elements at the end such that the size becomes count. New elements are value initialized.

    Throws. 

    • If T's value initialization throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    count

    The number of elements which will be stored in the container.

    Requires:

    count <= capacity()

  4. void ( count, default_init_t);
    Inserts or erases elements at the end such that the size becomes count. New elements are default initialized.

    Throws. 

    • If T's default initialization throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Note. Non-standard extension

    Parameters:

    count

    The number of elements which will be stored in the container.

    Requires:

    count <= capacity()

  5. void ( count, const & value);
    Inserts or erases elements at the end such that the size becomes count. New elements are copy constructed from value.

    Throws. 

    • If T's copy constructor throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    count

    The number of elements which will be stored in the container.

    value

    The value used to copy construct the new element.

    Requires:

    count <= capacity()

  6. void ( count);
    This call has no effect because the Capacity of this container is constant.

    Throws. If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Constant O(1).

    Parameters:

    count

    The number of elements which the container should be able to contain.

    Requires:

    count <= capacity()

  7. void (const & value);
    Adds a copy of value at the end.

    Throws. 

    • If T's copy constructor throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Constant O(1).

    Parameters:

    value

    The value used to copy construct the new element.

    Requires:

    size() < capacity()

  8. void ( value);
    Moves value to the end.

    Throws. 

    • If T's move constructor throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Constant O(1).

    Parameters:

    value

    The value to move construct the new element.

    Requires:

    size() < capacity()

  9. void () ;
    Destroys last value and decreases the size.

    Throws. Nothing.

    Complexity. Constant O(1).

    Requires:

    !empty()

  10.  ( p, const & value);
    Inserts a copy of element at p.

    Throws. 

    • If T's copy constructor or copy assignment throws

    • If T's move constructor or move assignment throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Constant or linear.

    Parameters:

    p

    The position at which the new value will be inserted.

    value

    The value used to copy construct the new element.

    Requires:

    • p must be a valid iterator of *this in range [begin(), end()].

    • size() < capacity()

  11.  ( p,  value);
    Inserts a move-constructed element at p.

    Throws. 

    • If T's move constructor or move assignment throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Constant or linear.

    Parameters:

    p

    The position at which the new value will be inserted.

    value

    The value used to move construct the new element.

    Requires:

    • p must be a valid iterator of *this in range [begin(), end()].

    • size() < capacity()

  12.  ( p,  count, const & value);
    Inserts a count copies of value at p.

    Throws. 

    • If T's copy constructor or copy assignment throws.

    • If T's move constructor or move assignment throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    count

    The number of new elements which will be inserted.

    p

    The position at which new elements will be inserted.

    value

    The value used to copy construct new elements.

    Requires:

    • p must be a valid iterator of *this in range [begin(), end()].

    • size() + count <= capacity()

  13. template<typename Iterator> 
       ( p, Iterator first, Iterator last);
    Inserts a copy of a range [first, last) at p.

    Throws. 

    • If T's constructor and assignment taking a dereferenced Iterator.

    • If T's move constructor or move assignment throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    first

    The iterator to the first element of a range used to construct new elements.

    last

    The iterator to the one after the last element of a range used to construct new elements.

    p

    The position at which new elements will be inserted.

    Requires:

    • p must be a valid iterator of *this in range [begin(), end()].

    • distance(first, last) <= capacity()

    • Iterator must meet the ForwardTraversalIterator concept.

  14.  ( p,  il);
    Inserts a copy of a range [il.begin(), il.end()) at p.

    Throws. 

    • If T's constructor and assignment taking a dereferenced std::initializer_list iterator.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    il

    The std::initializer_list which contains elements that will be inserted.

    p

    The position at which new elements will be inserted.

    Requires:

    • p must be a valid iterator of *this in range [begin(), end()].

    • distance(il.begin(), il.end()) <= capacity()

  15.  ( p);
    Erases T from p.

    Throws. If T's move assignment throws.

    Complexity. Linear O(N).

    Parameters:

    p

    The position of the element which will be erased from the container.

    Requires:

    p must be a valid iterator of *this in range [begin(), end())

  16.  ( first,  last);
    Erases Values from a range [first, last).

    Throws. If T's move assignment throws.

    Complexity. Linear O(N).

    Parameters:

    first

    The position of the first element of a range which will be erased from the container.

    last

    The position of the one after the last element of a range which will be erased from the container.

    Requires:

    • first and last must define a valid range

    • iterators must be in range [begin(), end()]

  17. template<typename Iterator> void (Iterator first, Iterator last);
    Assigns a range [first, last) of Values to this container.

    Throws. 

    • If T's copy constructor or copy assignment throws,

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    first

    The iterator to the first element of a range used to construct new content of this container.

    last

    The iterator to the one after the last element of a range used to construct new content of this container.

    Requires:

    distance(first, last) <= capacity()

  18. void ( il);
    Assigns a range [il.begin(), il.end()) of Values to this container.

    Throws. 

    • If T's copy constructor or copy assignment throws,

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    il

    std::initializer_list with values used to construct new content of this container.

    Requires:

    distance(il.begin(), il.end()) <= capacity()

  19. void ( count, const & value);
    Assigns a count copies of value to this container.

    Throws. 

    • If T's copy constructor or copy assignment throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Linear O(N).

    Parameters:

    count

    The new number of elements which will be container in the container.

    value

    The value which will be used to copy construct the new content.

    Requires:

    count <= capacity()

  20. template< Args>  (Args &&... args);
    Inserts a T constructed with std::forward<Args>(args)... in the end of the container.

    Throws. 

    • If in-place constructor throws or T's move constructor throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Constant O(1).

    Parameters:

    args

    The arguments of the constructor of the new element which will be created at the end of the container.

    Requires:

    size() < capacity()

    Returns:

    A reference to the created object.

  21. template< Args>  ( p, Args &&... args);
    Inserts a T constructed with std::forward<Args>(args)... before p.

    Throws. 

    • If in-place constructor throws or if T's move constructor or move assignment throws.

    • If throw_on_overflow<true> option is set and the container runs out of capacity.

    Complexity. Constant or linear.

    Parameters:

    args

    The arguments of the constructor of the new element.

    p

    The position at which new elements will be inserted.

    Requires:

    • p must be a valid iterator of *this in range [begin(), end()]

    • size() < capacity()

  22. void () ;
    Removes all elements from the container.

    Throws. Nothing.

    Complexity. Constant O(1).

  23.  ( i);
    Returns reference to the i-th element.

    Throws. out_of_range exception by default.

    Complexity. Constant O(1).

    Parameters:

    i

    The element's index.

    Requires:

    i < size()

    Returns:

    reference to the i-th element from the beginning of the container.

  24.  ( i) ;
    Returns const reference to the i-th element.

    Throws. out_of_range exception by default.

    Complexity. Constant O(1).

    Parameters:

    i

    The element's index.

    Requires:

    i < size()

    Returns:

    const reference to the i-th element from the beginning of the container.

  25.  ( i) ;
    Returns reference to the i-th element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Parameters:

    i

    The element's index.

    Requires:

    i < size()

    Returns:

    reference to the i-th element from the beginning of the container.

  26.  ( i) ;
    Returns const reference to the i-th element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Parameters:

    i

    The element's index.

    Requires:

    i < size()

    Returns:

    const reference to the i-th element from the beginning of the container.

  27.  ( i) ;
    Returns a iterator to the i-th element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Parameters:

    i

    The element's index.

    Requires:

    i =< size()

    Returns:

    a iterator to the i-th element.

  28.  ( i) ;
    Returns a const_iterator to the i-th element.

    Throws. Nothing by default.

    Complexity. Constant O(1).

    Parameters:

    i

    The element's index.

    Requires:

    i =< size()

    Returns:

    a const_iterator to the i-th element.

  29.  ( p) ;
    Returns the index of the element pointed by p.

    Throws. Nothing.

    Complexity. Constant O(1).

    Parameters:

    p

    An iterator to the element.

    Requires:

    begin() <= p <= end()

    Returns:

    The index of the element pointed by p.

  30.  ( p) ;
    Returns the index of the element pointed by p.

    Throws. Nothing.

    Complexity. Constant O(1).

    Parameters:

    p

    A const_iterator to the element.

    Requires:

    begin() <= p <= end()

    Returns:

    a const_iterator to the i-th element.

  31.  () ;
    Returns reference to the first element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Requires:

    !empty()

    Returns:

    reference to the first element from the beginning of the container.

  32.  () ;
    Returns const reference to the first element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Requires:

    !empty()

    Returns:

    const reference to the first element from the beginning of the container.

  33.  () ;
    Returns reference to the last element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Requires:

    !empty()

    Returns:

    reference to the last element from the beginning of the container.

  34.  () ;
    Returns const reference to the first element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Requires:

    !empty()

    Returns:

    const reference to the last element from the beginning of the container.

  35. T * () ;
    Pointer such that [data(), data() + size()) is a valid range. For a non-empty vector data() == &front().

    Throws. Nothing.

    Complexity. Constant O(1).

  36. const T * () ;
    Const pointer such that [data(), data() + size()) is a valid range. For a non-empty vector data() == &front().

    Throws. Nothing.

    Complexity. Constant O(1).

  37.  () ;
    Returns iterator to the first element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    iterator to the first element contained in the vector.

  38.  () ;
    Returns const iterator to the first element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    const_iterator to the first element contained in the vector.

  39.  () ;
    Returns const iterator to the first element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    const_iterator to the first element contained in the vector.

  40.  () ;
    Returns iterator to the one after the last element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    iterator pointing to the one after the last element contained in the vector.

  41.  () ;
    Returns const iterator to the one after the last element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    const_iterator pointing to the one after the last element contained in the vector.

  42.  () ;
    Returns const iterator to the one after the last element.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    const_iterator pointing to the one after the last element contained in the vector.

  43.  () ;
    Returns reverse iterator to the first element of the reversed container.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    reverse_iterator pointing to the beginning of the reversed static_vector.

  44.  () ;
    Returns const reverse iterator to the first element of the reversed container.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    const_reverse_iterator pointing to the beginning of the reversed static_vector.

  45.  () ;
    Returns const reverse iterator to the first element of the reversed container.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    const_reverse_iterator pointing to the beginning of the reversed static_vector.

  46.  () ;
    Returns reverse iterator to the one after the last element of the reversed container.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    reverse_iterator pointing to the one after the last element of the reversed static_vector.

  47.  () ;
    Returns const reverse iterator to the one after the last element of the reversed container.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    const_reverse_iterator pointing to the one after the last element of the reversed static_vector.

  48.  () ;
    Returns const reverse iterator to the one after the last element of the reversed container.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    const_reverse_iterator pointing to the one after the last element of the reversed static_vector.

  49.  () ;
    Returns the number of stored elements.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    Number of elements contained in the container.

  50. bool () ;
    Queries if the container contains elements.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    true if the number of elements contained in the container is equal to 0.

static_vector public static functions

  1.  () ;
    Returns container's capacity.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    container's capacity.

  2.  () ;
    Returns container's capacity.

    Throws. Nothing.

    Complexity. Constant O(1).

    Returns:

    container's capacity.


PrevUpHomeNext