bsl::vector

STL-compliant sequence container conforming to the bslma model.

Synopsis

Declared in <bslstl_vector.h>

template<
    class VALUE_TYPE,
    class ALLOCATOR = allocator<VALUE_TYPE>>
class vector
    : public vectorBase<VALUE_TYPE>

Description

This class template provides an STL-compliant vector that conforms to the bslma::Allocator model. For the requirements of a vector class, consult the C++11 standard. In particular, this implementation offers the general rules that:

1. A call to any method that would result in a vector having a size or capacity greater than the value returned by max_size triggers a call to bslstl::StdExceptUtil::throwLengthError. 2. A call to an at method that attempts to access a position outside of the valid range of a vector triggers a call to bslstl::StdExceptUtil::throwOutOfRange.

Note that portions of the standard methods are implemented in vectorBase, which is parameterized on only VALUE_TYPE in order to generate smaller debug strings.

This class: * supports a complete set of value-semantic operations

  • except for BDEX serialization * is exception-neutral * is alias-safe * is const thread-safe For terminology see {bsldoc_glossary}.

In addition, the following members offer a full guarantee of rollback: if an exception is thrown during the invocation of push_back or insert with a single element at the end of a pre-existing object, the object is left in a valid state and its value is unchanged.

Base Classes

NameDescription
vectorBase<VALUE_TYPE>Allocator-independent storage layout shared by vector.

Type Aliases

NameDescription
allocator_type This typedef is an alias to the (template parameter) ALLOCATOR.
const_iterator This typedef is an alias to VALUE_TYPE const *.
const_pointer This typedef is an alias to AllocatorTraits::const_pointer.
const_reference This typedef is an alias to VALUE_TYPE const&.
const_reverse_iterator This typedef is an alias to bsl::reverse_iterator<const_iterator>.
difference_type This typedef is an alias to AllocatorTraits::difference_type.
iterator This typedef is an alias to VALUE_TYPE *.
pointer This typedef is an alias to AllocatorTraits::pointer.
reference This typedef is an alias to VALUE_TYPE&.
reverse_iterator This typedef is an alias to bsl::reverse_iterator<iterator>.
size_type This typedef is an alias to AllocatorTraits::size_type.
value_type This typedef is an alias to the (template parameter) VALUE_TYPE.

Member Functions

NameDescription
vector [constructor]Constructors
~vector [destructor]Destroy this vector.
operator= Assignment operators
adopt Adopt memory allocations from the specified base object.
append_range Append elements from a range to this vector.
assign Assign a new value to this vector.
assign_range Assign elements from a range to this vector.
at at overloads
back back overloads
begin begin overloads
capacity Return the capacity of this vector, i.e., the maximum number of elements for which resizing is guaranteed not to trigger a reallocation.
cbegin Return a const iterator to the first element.
cend Return the past-the-end (forward) iterator providing non-modifiable access to this vector.
clear Remove all elements from this vector.
crbegin Return a reverse iterator providing non-modifiable access to the last element in this vector, and the past-the-end reverse iterator if this vector is empty.
crend Return the past-the-end reverse iterator providing non-modifiable access to this vector.
data data overloads
emplace Emplace a newly constructed element at the specified position.
emplace_back Emplace a newly constructed element at the end.
empty Return true if this vector has size 0, and false otherwise.
end end overloads
erase Erase elements from this vector.
front front overloads
get_allocator Return (a copy of) the allocator used for memory allocation by this vector.
insert insert overloads
insert_range Insert the elements of range before position.
max_size Return a theoretical upper bound on this vector's size.
operator[] Subscript operators
pop_back Erase the last element from this vector. The behavior is undefined if this vector is empty.
push_back push_back overloads
rbegin rbegin overloads
rend rend overloads
reserve Increase capacity to at least newCapacity if needed.
resize resize overloads
shrink_to_fit Request that unused capacity be released.
size Return the number of elements in this vector.
swap Exchange the value of this object with other.

Protected Data Members

NameDescription
d_capacity Capacity of data storage in number of elements.
d_dataBegin_p Beginning of data storage (owned).
d_dataEnd_p One past the end of data storage.

Specializations

NameDescription
vector<VALUE_TYPE*, ALLOCATOR> This partial specialization of vector for pointer types to a (template parameter) VALUE_TYPE type is implemented in terms of vector<UintPtr> to reduce.

Deduction Guides

NameDescription
vector<VALUE> Deduce the template parameter VALUE from the value_type of the iterators supplied to the constructor of vector.
vector<VALUE> Deduce template arguments for vector from constructor arguments.
vector<VALUE> Deduce the template parameter VALUE from the value_type of the iterators supplied to the constructor of vector.
vector<VALUE> Deduce the template parameter VALUE from the corresponding parameter supplied to the constructor of vector.
vector<VALUE, ALLOCATOR> Deduce the template parameter VALUE from the value_type of the iterators supplied to the constructor of vector.
vector<ranges::range_value_t<t_RANGE>, t_ALLOCATOR> Deduce the template parameters VALUE_TYPE and ALLOCATOR from the parameters supplied to the constructor of vector.

Non-Member Functions

NameDescription
bdlat_valueTypeAssignAssign the specified rhs vector to the specified lhs vector.
eraseErase all the elements in the specified vector vec that compare equal to the specified value. Return the number of elements erased.
erase_ifErase all the elements in the specified vector vec that satisfy the specified predicate predicate. Return the number of elements erased.
operator<=>Perform a three-way comparison of the operands.
operator==Return whether the operands have the same value.
swapExchange the contents of two vectors.
::BloombergLP::bdlat_ArrayFunctions::bdlat_arrayAccessElementInvoke the specified accessor on the element at the specified index of the specified array. Return the value from the invocation of accessor.
::BloombergLP::bdlat_ArrayFunctions::bdlat_arrayManipulateElementApply the specified manipulator to the element at the specified index in the specified array.
::BloombergLP::bdlat_ArrayFunctions::bdlat_arrayReserveReserve capacity for the specified array to hold at least the specified numElements elements.
::BloombergLP::bdlat_ArrayFunctions::bdlat_arrayResizeResize the specified array to contain the specified newSize elements.
::BloombergLP::bdlat_ArrayFunctions::bdlat_arraySizeReturn the number of elements in the specified array.
::BloombergLP::bdlat_ArrayFunctions::bdlat_arraySupportsReserveReturn true if the specified array supports the reserve method.
::BloombergLP::bdlat_ArrayIterators::backInserterSpecialization of backInserter for bsl::vector. Return bsl::back_insert_iterator instead of BackInsertIterator.