Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template small_vector_base

boost::container::small_vector_base

Synopsis

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

template<typename T, typename SecAlloc, typename Options> 
class small_vector_base {
public:
  // types
  typedef T                                                   value_type;            
  typedef implementation_defined                              allocator_type;        
  typedef allocator_traits< allocator_type >::pointer         pointer;               
  typedef allocator_traits< allocator_type >::const_pointer   const_pointer;         
  typedef allocator_traits< allocator_type >::reference       reference;             
  typedef allocator_traits< allocator_type >::const_reference const_reference;       
  typedef allocator_traits< allocator_type >::size_type       size_type;             
  typedef allocator_traits< allocator_type >::difference_type difference_type;       
  typedef allocator_type                                      stored_allocator_type; 
  typedef implementation_defined                              iterator;              
  typedef implementation_defined                              const_iterator;        
  typedef implementation_defined                              reverse_iterator;      
  typedef implementation_defined                              const_reverse_iterator;

  // Functionality inherited from boost::container::vector
  template<typename InIt> void assign(InIt, InIt);
  void assign(std::initializer_list< T >);
  template<typename FwdIt> void assign(FwdIt, FwdIt);
  void assign(size_type, const value_type &);
  allocator_type get_allocator() const noexcept;
  stored_allocator_type & get_stored_allocator() noexcept;
  const stored_allocator_type & get_stored_allocator() const noexcept;
  iterator begin() noexcept;
  const_iterator begin() const noexcept;
  iterator end() noexcept;
  const_iterator end() const noexcept;
  reverse_iterator rbegin() noexcept;
  const_reverse_iterator rbegin() const noexcept;
  reverse_iterator rend() noexcept;
  const_reverse_iterator rend() const noexcept;
  const_iterator cbegin() const noexcept;
  const_iterator cend() const noexcept;
  const_reverse_iterator crbegin() const noexcept;
  const_reverse_iterator crend() const noexcept;
  bool empty() const noexcept;
  size_type size() const noexcept;
  size_type max_size() const noexcept;
  void resize(size_type);
  void resize(size_type, default_init_t);
  void resize(size_type, const T &);
  size_type capacity() const noexcept;
  void reserve(size_type);
  void shrink_to_fit();
  reference front() noexcept;
  const_reference front() const noexcept;
  reference back() noexcept;
  const_reference back() const noexcept;
  reference operator[](size_type) noexcept;
  const_reference operator[](size_type) const noexcept;
  iterator nth(size_type) noexcept;
  const_iterator nth(size_type) const noexcept;
  size_type index_of(iterator) noexcept;
  size_type index_of(const_iterator) const noexcept;
  reference at(size_type);
  const_reference at(size_type) const;
  T * data() noexcept;
  const T * data() const noexcept;
  template<class ... Args> reference emplace_back(Args &&...);
  template<class ... Args> bool stable_emplace_back(Args &&...);
  template<class ... Args> reference unchecked_emplace_back(Args &&...);
  template<class ... Args> iterator emplace(const_iterator, Args &&...);
  void push_back(const T &);
  void push_back(T &&);
  void unchecked_push_back(const T &);
  void unchecked_push_back(T &&);
  iterator insert(const_iterator, const T &);
  iterator insert(const_iterator, T &&);
  iterator insert(const_iterator, size_type, const T &);
  template<typename InIt> iterator insert(const_iterator, InIt, InIt);
  iterator insert(const_iterator, std::initializer_list< value_type >);
  void pop_back() noexcept;
  iterator erase(const_iterator);
  iterator erase(const_iterator, const_iterator);
  void clear() noexcept;

  // public member functions
  small_vector_base & operator=(const small_vector_base &);
  small_vector_base & operator=(small_vector_base &&);
  void swap(small_vector_base &);
};

Description

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 Functionality inherited from boost::container::vector

  1. template<typename InIt> void assign(InIt first, InIt last);
  2. void assign(std::initializer_list< T > il);

    Effects: Assigns the the range [il.begin(), il.end()) to *this.

    Throws: If memory allocation throws or T's constructor from dereferencing iniializer_list iterator throws.

  3. template<typename FwdIt> void assign(FwdIt first, FwdIt last);

    Effects: Assigns the the range [first, last) to *this.

    Throws: If memory allocation throws or T's copy/move constructor/assignment or T's constructor/assignment from dereferencing InpIt throws.

    Complexity: Linear to n.

  4. void assign(size_type n, const value_type & val);

    Effects: Assigns the n copies of val to *this.

    Throws: If memory allocation throws or T's copy/move constructor/assignment throws.

    Complexity: Linear to n.

  5. allocator_type get_allocator() const noexcept;

    Effects: Returns a copy of the internal allocator.

    Throws: If allocator's copy constructor throws.

    Complexity: Constant.

  6. stored_allocator_type & get_stored_allocator() noexcept;

    Effects: Returns a reference to the internal allocator.

    Throws: Nothing

    Complexity: Constant.

    Note: Non-standard extension.

  7. const stored_allocator_type & get_stored_allocator() const noexcept;

    Effects: Returns a reference to the internal allocator.

    Throws: Nothing

    Complexity: Constant.

    Note: Non-standard extension.

  8. iterator begin() noexcept;

    Effects: Returns an iterator to the first element contained in the vector.

    Throws: Nothing.

    Complexity: Constant.

  9. const_iterator begin() const noexcept;

    Effects: Returns a const_iterator to the first element contained in the vector.

    Throws: Nothing.

    Complexity: Constant.

  10. iterator end() noexcept;

    Effects: Returns an iterator to the end of the vector.

    Throws: Nothing.

    Complexity: Constant.

  11. const_iterator end() const noexcept;

    Effects: Returns a const_iterator to the end of the vector.

    Throws: Nothing.

    Complexity: Constant.

  12. reverse_iterator rbegin() noexcept;

    Effects: Returns a reverse_iterator pointing to the beginning of the reversed vector.

    Throws: Nothing.

    Complexity: Constant.

  13. const_reverse_iterator rbegin() const noexcept;

    Effects: Returns a const_reverse_iterator pointing to the beginning of the reversed vector.

    Throws: Nothing.

    Complexity: Constant.

  14. reverse_iterator rend() noexcept;

    Effects: Returns a reverse_iterator pointing to the end of the reversed vector.

    Throws: Nothing.

    Complexity: Constant.

  15. const_reverse_iterator rend() const noexcept;

    Effects: Returns a const_reverse_iterator pointing to the end of the reversed vector.

    Throws: Nothing.

    Complexity: Constant.

  16. const_iterator cbegin() const noexcept;

    Effects: Returns a const_iterator to the first element contained in the vector.

    Throws: Nothing.

    Complexity: Constant.

  17. const_iterator cend() const noexcept;

    Effects: Returns a const_iterator to the end of the vector.

    Throws: Nothing.

    Complexity: Constant.

  18. const_reverse_iterator crbegin() const noexcept;

    Effects: Returns a const_reverse_iterator pointing to the beginning of the reversed vector.

    Throws: Nothing.

    Complexity: Constant.

  19. const_reverse_iterator crend() const noexcept;

    Effects: Returns a const_reverse_iterator pointing to the end of the reversed vector.

    Throws: Nothing.

    Complexity: Constant.

  20. bool empty() const noexcept;

    Effects: Returns true if the vector contains no elements.

    Throws: Nothing.

    Complexity: Constant.

  21. size_type size() const noexcept;

    Effects: Returns the number of the elements contained in the vector.

    Throws: Nothing.

    Complexity: Constant.

  22. size_type max_size() const noexcept;

    Effects: Returns the largest possible size of the vector.

    Throws: Nothing.

    Complexity: Constant.

  23. void resize(size_type new_size);

    Effects: Inserts or erases elements at the end such that the size becomes n. New elements are value initialized.

    Throws: If memory allocation throws, or T's copy/move or value initialization throws.

    Complexity: Linear to the difference between size() and new_size.

  24. void resize(size_type new_size, default_init_t);

    Effects: Inserts or erases elements at the end such that the size becomes n. New elements are default initialized.

    Throws: If memory allocation throws, or T's copy/move or default initialization throws.

    Complexity: Linear to the difference between size() and new_size.

    Note: Non-standard extension

  25. void resize(size_type new_size, const T & x);

    Effects: Inserts or erases elements at the end such that the size becomes n. New elements are copy constructed from x.

    Throws: If memory allocation throws, or T's copy/move constructor throws.

    Complexity: Linear to the difference between size() and new_size.

  26. size_type capacity() const noexcept;

    Effects: Number of elements for which memory has been allocated. capacity() is always greater than or equal to size().

    Throws: Nothing.

    Complexity: Constant.

  27. void reserve(size_type new_cap);

    Effects: If n is less than or equal to capacity(), this call has no effect. Otherwise, it is a request for allocation of additional memory. If the request is successful, then capacity() is greater than or equal to n; otherwise, capacity() is unchanged. In either case, size() is unchanged.

    Throws: If memory allocation allocation throws or T's copy/move constructor throws.

  28. void shrink_to_fit();

    Effects: Tries to deallocate the excess of memory created with previous allocations. The size of the vector is unchanged

    Throws: If memory allocation throws, or T's copy/move constructor throws.

    Complexity: Linear to size().

  29. reference front() noexcept;

    Requires: !empty()

    Effects: Returns a reference to the first element of the container.

    Throws: Nothing.

    Complexity: Constant.

  30. const_reference front() const noexcept;

    Requires: !empty()

    Effects: Returns a const reference to the first element of the container.

    Throws: Nothing.

    Complexity: Constant.

  31. reference back() noexcept;

    Requires: !empty()

    Effects: Returns a reference to the last element of the container.

    Throws: Nothing.

    Complexity: Constant.

  32. const_reference back() const noexcept;

    Requires: !empty()

    Effects: Returns a const reference to the last element of the container.

    Throws: Nothing.

    Complexity: Constant.

  33. reference operator[](size_type n) noexcept;

    Requires: size() > n.

    Effects: Returns a reference to the nth element from the beginning of the container.

    Throws: Nothing.

    Complexity: Constant.

  34. const_reference operator[](size_type n) const noexcept;

    Requires: size() > n.

    Effects: Returns a const reference to the nth element from the beginning of the container.

    Throws: Nothing.

    Complexity: Constant.

  35. iterator nth(size_type n) noexcept;

    Requires: size() >= n.

    Effects: Returns an iterator to the nth element from the beginning of the container. Returns end() if n == size().

    Throws: Nothing.

    Complexity: Constant.

    Note: Non-standard extension

  36. const_iterator nth(size_type n) const noexcept;

    Requires: size() >= n.

    Effects: Returns a const_iterator to the nth element from the beginning of the container. Returns end() if n == size().

    Throws: Nothing.

    Complexity: Constant.

    Note: Non-standard extension

  37. size_type index_of(iterator p) noexcept;

    Requires: begin() <= p <= end().

    Effects: Returns the index of the element pointed by p and size() if p == end().

    Throws: Nothing.

    Complexity: Constant.

    Note: Non-standard extension

  38. size_type index_of(const_iterator p) const noexcept;

    Requires: begin() <= p <= end().

    Effects: Returns the index of the element pointed by p and size() if p == end().

    Throws: Nothing.

    Complexity: Constant.

    Note: Non-standard extension

  39. reference at(size_type n);

    Requires: size() > n.

    Effects: Returns a reference to the nth element from the beginning of the container.

    Throws: range_error if n >= size()

    Complexity: Constant.

  40. const_reference at(size_type n) const;

    Requires: size() > n.

    Effects: Returns a const reference to the nth element from the beginning of the container.

    Throws: range_error if n >= size()

    Complexity: Constant.

  41. T * data() noexcept;

    Returns: A pointer such that [data(),data() + size()) is a valid range. For a non-empty vector, data() == &front().

    Throws: Nothing.

    Complexity: Constant.

  42. const T * data() const noexcept;

    Returns: A pointer such that [data(),data() + size()) is a valid range. For a non-empty vector, data() == &front().

    Throws: Nothing.

    Complexity: Constant.

  43. template<class ... Args> reference emplace_back(Args &&... args);

    Effects: Inserts an object of type T constructed with std::forward<Args>(args)... in the end of the vector.

    Returns: A reference to the created object.

    Throws: If memory allocation throws or the in-place constructor throws or T's copy/move constructor throws.

    Complexity: Amortized constant time.

  44. template<class ... Args> bool stable_emplace_back(Args &&... args);

    Effects: Inserts an object of type T constructed with std::forward<Args>(args)... in the end of the vector.

    Throws: If the in-place constructor throws.

    Complexity: Constant time.

    Note: Non-standard extension.

  45. template<class ... Args> reference unchecked_emplace_back(Args &&... args);

    Requires: Before the call to this function size() < capacity() must be true. Otherwise, the behavior is undefined.

    Effects: Inserts an object of type T constructed with std::forward<Args>(args)... in the end of the vector.

    Throws: If the in-place constructor throws.

    Complexity: Constant time.

    Note: Non-standard extension.

  46. template<class ... Args> 
      iterator emplace(const_iterator position, Args &&... args);

    Requires: position must be a valid iterator of *this.

    Effects: Inserts an object of type T constructed with std::forward<Args>(args)... before position

    Throws: If memory allocation throws or the in-place constructor throws or T's copy/move constructor/assignment throws.

    Complexity: If position is end(), amortized constant time Linear time otherwise.

  47. void push_back(const T & x);

    Effects: Inserts a copy of x at the end of the vector.

    Throws: If memory allocation throws or T's copy/move constructor throws.

    Complexity: Amortized constant time.

  48. void push_back(T && x);

    Effects: Constructs a new element in the end of the vector and moves the resources of x to this new element.

    Throws: If memory allocation throws or T's copy/move constructor throws.

    Complexity: Amortized constant time.

  49. void unchecked_push_back(const T & x);

    Requires: Before the call to this function size() < capacity() must be true. Otherwise, the behavior is undefined.

    Effects: Inserts a copy of x at the end of the vector.

    Throws: If T's copy/move constructor throws.

    Complexity: Constant time.

  50. void unchecked_push_back(T && x);

    Requires: Before the call to this function size() < capacity() must be true. Otherwise, the behavior is undefined.

    Effects: Constructs a new element in the end of the vector and moves the resources of x to this new element.

    Throws: If T's copy/move constructor throws.

    Complexity: Constant time.

  51. iterator insert(const_iterator position, const T & x);

    Requires: position must be a valid iterator of *this.

    Effects: Insert a copy of x before position.

    Throws: If memory allocation throws or T's copy/move constructor/assignment throws.

    Complexity: If position is end(), amortized constant time Linear time otherwise.

  52. iterator insert(const_iterator position, T && x);

    Requires: position must be a valid iterator of *this.

    Effects: Insert a new element before position with x's resources.

    Throws: If memory allocation throws.

    Complexity: If position is end(), amortized constant time Linear time otherwise.

  53. iterator insert(const_iterator p, size_type n, const T & x);

    Requires: p must be a valid iterator of *this.

    Effects: Insert n copies of x before pos.

    Returns: an iterator to the first inserted element or p if n is 0.

    Throws: If memory allocation throws or T's copy/move constructor throws.

    Complexity: Linear to n.

  54. template<typename InIt> 
      iterator insert(const_iterator pos, InIt first, InIt last);

    Requires: p must be a valid iterator of *this.

    Effects: Insert a copy of the [first, last) range before pos.

    Returns: an iterator to the first inserted element or pos if first == last.

    Throws: If memory allocation throws, T's constructor from a dereferenced InpIt throws or T's copy/move constructor/assignment throws.

    Complexity: Linear to boost::container::iterator_distance [first, last).

  55. iterator insert(const_iterator position, 
                    std::initializer_list< value_type > il);

    Requires: p must be a valid iterator of *this. num, must be equal to boost::container::iterator_distance(first, last)

    Effects: Insert a copy of the [first, last) range before pos.

    Returns: an iterator to the first inserted element or pos if first == last.

    Throws: If memory allocation throws, T's constructor from a dereferenced InpIt throws or T's copy/move constructor/assignment throws.

    Complexity: Linear to boost::container::iterator_distance [first, last).

    Note: This function avoids a linear operation to calculate boost::container::iterator_distance[first, last) for forward and bidirectional iterators, and a one by one insertion for input iterators. This is a a non-standard extension.

    Requires: position must be a valid iterator of *this.

    Effects: Insert a copy of the [il.begin(), il.end()) range before position.

    Returns: an iterator to the first inserted element or position if first == last.

    Complexity: Linear to the range [il.begin(), il.end()).

    Requires: position must be a valid iterator of *this.

    Effects: Insert a copy of the [il.begin(), il.end()) range before position.

    Returns: an iterator to the first inserted element or position if first == last.

    Complexity: Linear to the range [il.begin(), il.end()).

  56. void pop_back() noexcept;

    Effects: Removes the last element from the container.

    Throws: Nothing.

    Complexity: Constant time.

  57. iterator erase(const_iterator position);

    Effects: Erases the element at position pos.

    Throws: Nothing.

    Complexity: Linear to the elements between pos and the last element. Constant if pos is the last element.

  58. iterator erase(const_iterator first, const_iterator last);

    Effects: Erases the elements pointed by [first, last).

    Throws: Nothing.

    Complexity: Linear to the distance between first and last plus linear to the elements between pos and the last element.

  59. void clear() noexcept;

    Effects: Erases all the elements of the vector. Leaves the capacity() of the vector unchanged.

    Throws: Nothing.

    Complexity: Linear to the number of elements in the container.

small_vector_base public member functions

  1. small_vector_base & operator=(const small_vector_base & other);

    Effects: Makes *this contain the same elements as other.

    Throws: If memory allocation throws or T's copy/move constructor/assignment throws.

    Complexity: Linear to the number of elements in other.

  2. small_vector_base & operator=(small_vector_base && other);

    Effects: Move assignment. Transfers other's elements to *this. If the source is using its internal storage, elements are moved one by one; otherwise resources are stolen.

    Throws: If T's move constructor/assignment throws when elements must be moved.

    Complexity: Linear to the number of elements in the internal storage, constant otherwise.

  3. void swap(small_vector_base & other);

    Effects: Swaps the contents of *this and other.

    Throws: Nothing unless elements must be moved between buffers and T's move throws.

    Complexity: Constant if both use heap storage, linear in the small buffers otherwise.


PrevUpHomeNext