Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.

[Home]vector

Synopsis

template<
      typename T1 = implementation-defined
    , typename T2 = implementation-defined
    , ...
    , typename Tn = implementation-defined
    >
struct vector
{
};

Description

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].

Example

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));

Definition

#include "boost/mpl/vector.hpp"
#include "boost/mpl/vector/vector0.hpp"
#include "boost/mpl/vector/vector10.hpp"
...
#include "boost/mpl/vector/vector50.hpp"

Notes

[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));


See also

Random Access Sequence, vector_c, list, list_c, range_c


Table of Contents
Last edited July 22, 2002 4:28 pm