![]() |
Home | Libraries | People | FAQ | More |
boost::container::small_vector
// 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, void, void > { public: // 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); 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(); 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); template<typename InIt> small_vector(InIt, InIt, const allocator_type &); 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 &&); 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 &&); small_vector & operator=(const base_type &); small_vector & operator=(base_type &&); void swap(small_vector &); void shrink_to_fit(); };
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.
Any change to the capacity of the vector, including decreasing its size such as with the shrink_to_fit method, will cause the vector to permanently switch to dynamically allocated storage.
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 = void
The allocator used for memory management when the number of elements exceeds N. Use void for the default allocator
typename Options = void
A type produced from boost::container::small_vector_options.
small_vector Functionality inherited from boost::container::vectortemplate<typename InIt> void assign(InIt first, InIt last);
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.
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.
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.
allocator_type get_allocator() const noexcept;
Effects: Returns a copy of the internal allocator.
Throws: If allocator's copy constructor throws.
Complexity: Constant.
stored_allocator_type & get_stored_allocator() noexcept;
Effects: Returns a reference to the internal allocator.
Throws: Nothing
Complexity: Constant.
Note: Non-standard extension.
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.
iterator begin() noexcept;
Effects: Returns an iterator to the first element contained in the vector.
Throws: Nothing.
Complexity: Constant.
const_iterator begin() const noexcept;
Effects: Returns a const_iterator to the first element contained in the vector.
Throws: Nothing.
Complexity: Constant.
iterator end() noexcept;
Effects: Returns an iterator to the end of the vector.
Throws: Nothing.
Complexity: Constant.
const_iterator end() const noexcept;
Effects: Returns a const_iterator to the end of the vector.
Throws: Nothing.
Complexity: Constant.
reverse_iterator rbegin() noexcept;
Effects: Returns a reverse_iterator pointing to the beginning of the reversed vector.
Throws: Nothing.
Complexity: Constant.
const_reverse_iterator rbegin() const noexcept;
Effects: Returns a const_reverse_iterator pointing to the beginning of the reversed vector.
Throws: Nothing.
Complexity: Constant.
reverse_iterator rend() noexcept;
Effects: Returns a reverse_iterator pointing to the end of the reversed vector.
Throws: Nothing.
Complexity: Constant.
const_reverse_iterator rend() const noexcept;
Effects: Returns a const_reverse_iterator pointing to the end of the reversed vector.
Throws: Nothing.
Complexity: Constant.
const_iterator cbegin() const noexcept;
Effects: Returns a const_iterator to the first element contained in the vector.
Throws: Nothing.
Complexity: Constant.
const_iterator cend() const noexcept;
Effects: Returns a const_iterator to the end of the vector.
Throws: Nothing.
Complexity: Constant.
const_reverse_iterator crbegin() const noexcept;
Effects: Returns a const_reverse_iterator pointing to the beginning of the reversed vector.
Throws: Nothing.
Complexity: Constant.
const_reverse_iterator crend() const noexcept;
Effects: Returns a const_reverse_iterator pointing to the end of the reversed vector.
Throws: Nothing.
Complexity: Constant.
bool empty() const noexcept;
Effects: Returns true if the vector contains no elements.
Throws: Nothing.
Complexity: Constant.
size_type size() const noexcept;
Effects: Returns the number of the elements contained in the vector.
Throws: Nothing.
Complexity: Constant.
size_type max_size() const noexcept;
Effects: Returns the largest possible size of the vector.
Throws: Nothing.
Complexity: Constant.
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.
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
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.
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.
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.
reference front() noexcept;
Requires: !empty()
Effects: Returns a reference to the first element of the container.
Throws: Nothing.
Complexity: Constant.
const_reference front() const noexcept;
Requires: !empty()
Effects: Returns a const reference to the first element of the container.
Throws: Nothing.
Complexity: Constant.
reference back() noexcept;
Requires: !empty()
Effects: Returns a reference to the last element of the container.
Throws: Nothing.
Complexity: Constant.
const_reference back() const noexcept;
Requires: !empty()
Effects: Returns a const reference to the last element of the container.
Throws: Nothing.
Complexity: Constant.
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.
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.
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
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
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
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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()).
void pop_back() noexcept;
Effects: Removes the last element from the container.
Throws: Nothing.
Complexity: Constant time.
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.
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.
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 public member functionssmall_vector();
Effects: Constructs an empty small_vector using its internal storage; no dynamic memory allocation is performed.
Throws: If the default constructor of the allocator throws.
Complexity: Constant.
explicit small_vector(const allocator_type & a);
Effects: Constructs an empty small_vector using the specified allocator.
Throws: Nothing.
Complexity: Constant.
explicit small_vector(size_type n);
Effects: Constructs a small_vector that will hold n value-initialized elements.
Throws: If allocation throws or T's value initialization throws.
Complexity: Linear to n.
small_vector(size_type n, const allocator_type & a);
Effects: Constructs a small_vector that will hold n value-initialized elements, using the specified allocator.
Throws: If allocation throws or T's value initialization throws.
Complexity: Linear to n.
small_vector(size_type n, default_init_t);
Effects: Constructs a small_vector that will hold n default-initialized elements.
Throws: If allocation throws or T's default initialization throws.
Complexity: Linear to n.
Note: Non-standard extension.
small_vector(size_type n, default_init_t, const allocator_type & a);
Effects: Constructs a small_vector that will hold n default-initialized elements, using the specified allocator.
Throws: If allocation throws or T's default initialization throws.
Complexity: Linear to n.
Note: Non-standard extension.
small_vector(size_type n, const value_type & v);
Effects: Constructs a small_vector that will hold n copies of v.
Throws: If allocation throws or T's copy constructor throws.
Complexity: Linear to n.
small_vector(size_type n, const value_type & v, const allocator_type & a);
Effects: Constructs a small_vector that will hold n copies of v, using the specified allocator.
Throws: If allocation throws or T's copy constructor throws.
Complexity: Linear to n.
template<typename InIt> small_vector(InIt first, InIt last);
Effects: Constructs a small_vector with a copy of the range [first, last).
Throws: If allocation throws or T's constructor from a dereferenced InIt throws.
Complexity: Linear to the distance between first and last.
template<typename InIt> small_vector(InIt first, InIt last, const allocator_type & a);
Effects: Constructs a small_vector with a copy of the range [first, last), using the specified allocator.
Throws: If allocation throws or T's constructor from a dereferenced InIt throws.
Complexity: Linear to the distance between first and last.
small_vector(const small_vector & other);
Effects: Copy constructs a small_vector. The allocator is obtained by calling allocator_traits::select_on_container_copy_construction on other's allocator.
Throws: If allocation throws or T's copy constructor throws.
Complexity: Linear to other.size().
small_vector(const small_vector & other, const allocator_type & a);
Effects: Copy constructs a small_vector using the specified allocator.
Throws: If allocation throws or T's copy constructor throws.
Complexity: Linear to other.size().
explicit small_vector(const base_type & other);
Effects: Copy constructs a small_vector from a small_vector_base (with any N). The allocator is obtained by calling allocator_traits::select_on_container_copy_construction on other's allocator.
Throws: If allocation throws or T's copy constructor throws.
Complexity: Linear to other.size().
explicit small_vector(base_type && other);
Effects: Move constructs a small_vector from a small_vector_base (with any N), transferring its allocator. If other holds dynamically allocated storage its resources are stolen; otherwise its elements are moved into this object's internal storage.
Throws: If T's move constructor throws when elements must be moved.
Complexity: Constant if other holds dynamic storage, linear to other.size() otherwise.
small_vector(small_vector && other);
Effects: Move constructs a small_vector. If other holds dynamically allocated storage its resources are stolen; otherwise its elements are moved into this object's internal storage.
Throws: If T's move constructor throws when elements must be moved.
Complexity: Constant if other holds dynamic storage, linear to other.size() otherwise.
small_vector(small_vector && other, const allocator_type & a);
Effects: Move constructs a small_vector using the specified allocator. If the storage can be transferred its resources are stolen; otherwise elements are moved.
Throws: If allocation throws or T's move constructor throws.
Complexity: Constant if the storage can be transferred, linear to other.size() otherwise.
small_vector(std::initializer_list< value_type > il, const allocator_type & a = allocator_type());
Effects: Constructs a small_vector with a copy of the elements in il, using the specified allocator.
Throws: If allocation throws or T's constructor from a dereferenced std::initializer_list iterator throws.
Complexity: Linear to il.size().
small_vector & operator=(const small_vector & other);
Effects: Makes *this contain the same elements as other.
Throws: If allocation throws or T's copy/move constructor/assignment throws.
Complexity: Linear to the number of elements in other.
small_vector & operator=(small_vector && other);
Effects: Move assignment. Transfers other's elements to *this.
Throws: If T's move constructor/assignment throws when elements must be moved.
Complexity: Linear to the number of elements involved.
small_vector & operator=(const base_type & other);
Effects: Makes *this contain the same elements as other (a small_vector_base with any N).
Throws: If allocation throws or T's copy/move constructor/assignment throws.
Complexity: Linear to the number of elements in other.
small_vector & operator=(base_type && other);
Effects: Move assigns the elements of other (a small_vector_base with any N) to *this.
Throws: If T's move constructor/assignment throws when elements must be moved.
Complexity: Linear to the number of elements involved.
void swap(small_vector & other);
Effects: Swaps the contents of *this and other.
Complexity: Linear to the number of elements stored in the small buffers.
void shrink_to_fit();
Effects: Tries to reduce capacity() to the current size(). Once the capacity changes, the container permanently switches to dynamically allocated storage even if the resulting size would fit in the internal buffer.
Throws: If memory allocation throws or T's copy/move constructor throws.
Complexity: Linear to size().