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

The MPL Reference Manual: at
Front Page / Sequences / Intrinsic Metafunctions / at

at

Synopsis

template<
      typename Sequence
    , typename N
    >
struct at
{
    typedef unspecified type;
};

template<
      typename AssocSeq
    , typename Key
    , typename Default = unspecified
    >
struct at
{
    typedef unspecified type;
};

Description

at is an overloaded name:

  • at returns the N-th element from the beginning of the Forward Sequence Sequence.
  • at returns the first element associated with Key in the Associative Sequence AssocSeq, or Default if no such element exists.

Parameters

Parameter Requirement Description
Sequence Forward Sequence A sequence to be examined.
AssocSeq Associative Sequence A sequence to be examined.
N Integral Constant An offset from the beginning of the sequence specifying the element to be retrieved.
Key Any type A key for the element to be retrieved.
Default Any type A default value to return if the element is not found.

Expression semantics

For any Forward Sequence s, and Integral Constant n:

typedef at::type t;
Return type:

A type.

Precondition:

0 <= n::value < size::value.

Semantics:

Equivalent to

typedef deref< advance< begin::type,n >::type >::type t;

For any Associative Sequence s, and arbitrary types key and x:

typedef at::type t;
Return type:A type.
Semantics:If has_key::value == true, t is the value type associated with key; otherwise t is identical to x.
typedef at::type t;
Return type:

A type.

Semantics:

Equivalent to

typedef atvoid_>::type t;

Complexity

Sequence archetype Complexity
Forward Sequence Linear.
Random Access Sequence Amortized constant time.
Associative Sequence Amortized constant time.

Example

typedef range_c range;
BOOST_MPL_ASSERT_RELATION( (at< range, int_<0> >::value), ==, 10 );
BOOST_MPL_ASSERT_RELATION( (at< range, int_<10> >::value), ==, 20 );
BOOST_MPL_ASSERT_RELATION( (at< range, int_<40> >::value), ==, 50 );
typedef set< int const,long*,double > s;

BOOST_MPL_ASSERT(( is_same< at::type, void_ > ));
BOOST_MPL_ASSERT(( is_same< at::type, int > ));