.. Sequences/Classes//vector |10 vector ====== Description ----------- ``vector`` is a |variadic|, `random access`__, `extensible`__ sequence of types that supports constant-time insertion and removal of elements at both ends, and linear-time insertion and removal of elements in the middle. On compilers that support the ``typeof`` extension, ``vector`` is the simplest and in many cases the most efficient sequence. __ `Random Access Sequence`_ __ `Extensible Sequence`_ Header ------ +-------------------+-------------------------------------------------------+ | Sequence form | Header | +===================+=======================================================+ | Variadic | ``#include `` | +-------------------+-------------------------------------------------------+ | Numbered | ``#include `` | +-------------------+-------------------------------------------------------+ Model of -------- * |Variadic Sequence| * |Random Access Sequence| * |Extensible Sequence| * |Back Extensible Sequence| * |Front Extensible Sequence| Expression semantics -------------------- In the following table, ``v`` is an instance of ``vector``, ``pos`` and ``last`` are iterators into ``v``, ``r`` is a |Forward Sequence|, ``n`` is an |Integral Constant|, and ``x`` and |t1...tn| are arbitrary types. +---------------------------------------+-----------------------------------------------------------+ | Expression | Semantics | +=======================================+===========================================================+ | .. parsed-literal:: | ``vector`` of elements |t1...tn|; see | | | |Variadic Sequence|. | | vector<|t1...tn|> | | | vector\ *n*\ <|t1...tn|> | | +---------------------------------------+-----------------------------------------------------------+ | .. parsed-literal:: | Identical to ``vector``\ *n*\ ``<``\ |t1...tn|\ ``>``; | | | see |Variadic Sequence|. | | vector<|t1...tn|>::type | | | vector\ *n*\ <|t1...tn|>::type | | +---------------------------------------+-----------------------------------------------------------+ | ``begin::type`` | An iterator pointing to the beginning of ``v``; | | | see |Random Access Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``end::type`` | An iterator pointing to the end of ``v``; | | | see |Random Access Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``size::type`` | The size of ``v``; see |Random Access Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``empty::type`` | |true if and only if| the sequence is empty; | | | see |Random Access Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``front::type`` | The first element in ``v``; see | | | |Random Access Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``back::type`` | The last element in ``v``; see | | | |Random Access Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``at::type`` | The ``n``\ th element from the beginning of ``v``; see | | | |Random Access Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``insert::type`` | A new ``vector`` of following elements: | | | [``begin::type``, ``pos``), ``x``, | | | [``pos``, ``end::type``); see |Extensible Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``insert_range::type`` | A new ``vector`` of following elements: | | | [``begin::type``, ``pos``), | | | [``begin::type``, ``end::type``) | | | [``pos``, ``end::type``); see |Extensible Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``erase::type`` | A new ``vector`` of following elements: | | | [``begin::type``, ``pos``), | | | [``next::type``, ``end::type``); see | | | |Extensible Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``erase::type`` | A new ``vector`` of following elements: | | | [``begin::type``, ``pos``), | | | [``last``, ``end::type``); see |Extensible Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``clear::type`` | An empty ``vector``; see |Extensible Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``push_back::type`` | A new ``vector`` of following elements: | | | |begin/end|, ``x``; | | | see |Back Extensible Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``pop_back::type`` | A new ``vector`` of following elements: | | | [``begin::type``, ``prior< end::type >::type``); | | | see |Back Extensible Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``push_front::type`` | A new ``vector`` of following elements: | | | |begin/end|, ``x``; see |Front Extensible Sequence|. | +---------------------------------------+-----------------------------------------------------------+ | ``pop_front::type`` | A new ``vector`` of following elements: | | | [``next< begin::type >::type``, ``end::type``); | | | see |Front Extensible Sequence|. | +---------------------------------------+-----------------------------------------------------------+ Example ------- .. parsed-literal:: typedef vector floats; typedef push_back::type types; BOOST_MPL_ASSERT(( |is_same|\< at_c::type, int > )); See also -------- |Sequences|, |Variadic Sequence|, |Random Access Sequence|, |Extensible Sequence|, |vector_c|, |list|