...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
template< typename T1 = implementation-defined , typename T2 = implementation-defined , ... , typename Tn = implementation-defined > struct vector { };
An vector
is a Random Access Sequence of types. It's also an Extensible Sequence that supports constant time insertion and removal of elements at the end (through push_back
), and linear time insertion and removal of elements at the beginning or in the middle (through insert
/erase
algorithms). On compilers that support the typeof extension, vector is the simplest and in many cases the most efficient sequence [1].
typedef vector<float,double,long double> floats; typedef push_back<floating_types,my_float>::type ext_floats; typedef at_c<3,ext_floats>::type my; BOOST_STATIC_ASSERT((boost::is_same<my,my_float>::value));
#include "boost/mpl/vector.hpp" #include "boost/mpl/vector/vector0.hpp" #include "boost/mpl/vector/vector10.hpp" ... #include "boost/mpl/vector/vector50.hpp"
[1] The typeof
operator allows one to use overload resolution to implement a constant-time random access to elements of the sequence with minimum amount of code (in contrast to the usual brute-force approach the library has to resort to when the typeof
operator is not available):
struct null_node { static aux::type_wrapper<void_> item(...); };template< long N, typename T, typename Base > struct node : Base { using Base::item; static aux::type_wrapper<T> item(integral_c<long,N>); };
template< typename V, long N > struct at { typedef __typeof__(V::item(integral_c<long,N>())) wrapped_type_; typedef typename wrapped_type_::type type; };
typedef node<1,char,node<0,int,null_node> > v; typedef at<v,0>::type t; // constant-time random access! BOOST_STATIC_ASSERT((is_same<t,int>::value));
Random Access Sequence, vector_c
, list
, list_c
, range_c