Boost C++ Libraries 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.



      typename Sequence
struct size
    typedef unspecified type;


size returns the number of elements in the sequence, that is, the number of elements in the range [begin<Sequence>::type,end<Sequence>::type).


#include "boost/mpl/size.hpp"


 Parameter  Requirement  Description  
SequenceA model of Sequence

Expression semantics

 Expression  Expression type  Precondition  Semantics  Postcondition 
typedef size<Sequence>::type s;A model of Integral ConstantEquivalent to typedef distance< begin<Sequence>::type,end<Sequence>::type >::type s;s::value >= 0


The complexity of the size algorithm directly depends on the implementation of the particular sequence it is applied to. In the worst case size has a linear complexity. As a general rule, if the Sequence is a Random Access Sequence, you can be certain that size<Sequence>::type is an amortized constant time operation. The opposite is not necessary true - for example, a model of Forward Sequence still can guarantee you an amortized constant time size complexity. Please refer the documentation page of the concrete sequence type for further information.


typedef list0<> empty_list;
typedef vector_c<int,0,1,2,3,4,5> numbers;
typedef range_c<int,0,100> more_numbers;

BOOST_STATIC_ASSERT(size<list>::type::value == 0); BOOST_STATIC_ASSERT(size<numbers>::type::value == 5); BOOST_STATIC_ASSERT(size<more_numbers>::type::value == 100);

See also

Sequence, empty, begin, end

Table of Contents
Last edited July 17, 2002 3:51 am