![]() |
Home | Libraries | People | FAQ | More |
boost::container::small_vector_base
// 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 &); };
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::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.
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().
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_base public member functionssmall_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.
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.
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.