std::vector::get_allocator

allocator_type get_allocator() const; Returns the allocator associated with the container. Parameters (none). Return value The associated allocator. Complexity Constant.

std::vector::front

reference front(); const_reference front() const; Returns a reference to the first element in the container. Calling front on an empty container is undefined. Parameters (none). Return value reference to the first element. Complexity Constant. Notes For a container c, the expression c.front() is equivalent to *c.begin(). Example The following code uses front to display the first element of a std::vector<char>: #include <vector> #include <iostream>

std::vector::erase

(1) iterator erase( iterator pos ); (until C++11) iterator erase( const_iterator pos ); (since C++11) (2) iterator erase( iterator first, iterator last ); (until C++11) iterator erase( const_iterator first, const_iterator last ); (since C++11) Removes specified elements from the container. 1) Removes the element at pos. 2) Removes the elements in the range [first; last). Invalidates iterators and references at or after the point of the erase, including the end() iter

std::vector::end

iterator end(); const_iterator end() const; const_iterator cend() const; (since C++11) Returns an iterator to the element following the last element of the container. This element acts as a placeholder; attempting to access it results in undefined behavior. Parameters (none). Return value Iterator to the element following the last element. Exceptions (none) (until C++11) noexcept specification: noexcept (since C++11) Complexity Constant. See also begin

std::vector::empty

bool empty() const; Checks if the container has no elements, i.e. whether begin() == end(). Parameters (none). Return value true if the container is empty, false otherwise. Exceptions (none) (until C++11) noexcept specification: noexcept (since C++11) Complexity Constant. Example The following code uses empty to check if a std::vector<int> contains any elements: #include <vector> #include <iostream> int main() { std::vector<int> numbers;

std::vector::emplace_back

template< class... Args > void emplace_back( Args&&... args ); (since C++11) Appends a new element to the end of the container. The element is constructed through std::allocator_traits::construct, which typically uses placement-new to construct the element in-place at the location provided by the container. The arguments args... are forwarded to the constructor as std::forward<Args>(args).... If the new size() is greater than capacity() then all iterators and referen

std::vector::emplace

template< class... Args > iterator emplace( const_iterator pos, Args&&... args ); (since C++11) Inserts a new element into the container directly before pos. The element is constructed through std::allocator_traits::construct, which typically uses placement-new to construct the element in-place at a location provided by the container. The arguments args... are forwarded to the constructor as std::forward<Args>(args).... If the new size() is greater than capacity(),

std::vector::data

T* data(); (since C++11) const T* data() const; (since C++11) Returns pointer to the underlying array serving as element storage. The pointer is such that range [data(); data() + size()) is always a valid range, even if the container is empty. Parameters (none). Return value Pointer to the underlying element storage. For non-empty containers, returns &front(). Complexity Constant. Exceptions noexcept specification: noexcept See also front access the first

std::vector::clear

void clear(); Removes all elements from the container. Invalidates any references, pointers, or iterators referring to contained elements. May invalidate any past-the-end iterators. Leaves the capacity() of the vector unchanged. Parameters (none). Return value (none). Exceptions (none) (until C++11) noexcept specification: noexcept (since C++11) Complexity Linear in the size of the container. clear is defined in terms of erase, which has linear complexity. (until C++1

std::vector::capacity

size_type capacity() const; Returns the number of elements that the container has currently allocated space for. Parameters (none). Return value Capacity of the currently allocated storage. Exceptions (none) (until C++11) noexcept specification: noexcept (since C++11) Complexity Constant. See also size returns the number of elements (public member function) reserve reserves storage (public member function)