1 .. Sequences/Intrinsic Metafunctions//at
17 typedef |unspecified| type;
23 , typename Default = |unspecified|
27 typedef |unspecified| type;
34 ``at`` is an |overloaded name|:
36 * ``at<Sequence,N>`` returns the ``N``-th element from the beginning of the
37 |Forward Sequence| ``Sequence``.
39 * ``at<AssocSeq,Key,Default>`` returns the first element associated with ``Key``
40 in the |Associative Sequence| ``AssocSeq``, or ``Default`` if no such element
49 #include <boost/mpl/at.hpp>
55 |Tag Dispatched Metafunction|
61 +---------------+---------------------------+-----------------------------------------------+
62 | Parameter | Requirement | Description |
63 +===============+===========================+===============================================+
64 | ``Sequence`` | |Forward Sequence| | A sequence to be examined. |
65 +---------------+---------------------------+-----------------------------------------------+
66 | ``AssocSeq`` | |Associative Sequence| | A sequence to be examined. |
67 +---------------+---------------------------+-----------------------------------------------+
68 | ``N`` | |Integral Constant| | An offset from the beginning of the sequence |
69 | | | specifying the element to be retrieved. |
70 +---------------+---------------------------+-----------------------------------------------+
71 | ``Key`` | Any type | A key for the element to be retrieved. |
72 +---------------+---------------------------+-----------------------------------------------+
73 | ``Default`` | Any type | A default value to return if the element is |
75 +---------------+---------------------------+-----------------------------------------------+
82 :class: expression-semantics
84 For any |Forward Sequence| ``s``, and |Integral Constant| ``n``:
88 typedef at<s,n>::type t;
94 ``0 <= n::value < size<s>::value``.
101 typedef deref< advance< begin<s>::type,n >::type >::type t;
105 :class: expression-semantics
107 For any |Associative Sequence| ``s``, and arbitrary types ``key`` and ``x``:
111 typedef at<s,key,x>::type t;
117 If ``has_key<s,key>::value == true``, ``t`` is the value type associated with ``key``;
118 otherwise ``t`` is identical to ``x``.
121 .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
125 typedef at<s,key>::type t;
135 typedef at<s,key,void\_>::type t;
141 +-------------------------------+-----------------------------------+
142 | Sequence archetype | Complexity |
143 +===============================+===================================+
144 | |Forward Sequence| | Linear. |
145 +-------------------------------+-----------------------------------+
146 | |Random Access Sequence| | Amortized constant time. |
147 +-------------------------------+-----------------------------------+
148 | |Associative Sequence| | Amortized constant time. |
149 +-------------------------------+-----------------------------------+
156 typedef range_c<long,10,50> range;
157 BOOST_MPL_ASSERT_RELATION( (at< range, int_<0> >::value), ==, 10 );
158 BOOST_MPL_ASSERT_RELATION( (at< range, int_<10> >::value), ==, 20 );
159 BOOST_MPL_ASSERT_RELATION( (at< range, int_<40> >::value), ==, 50 );
164 typedef set< int const,long*,double > s;
166 BOOST_MPL_ASSERT(( is_same< at<s,char>::type, void\_ > ));
167 BOOST_MPL_ASSERT(( is_same< at<s,int>::type, int > ));
173 |Forward Sequence|, |Random Access Sequence|, |Associative Sequence|, |at_c|, |front|, |back|
176 .. copyright:: Copyright © 2001-2009 Aleksey Gurtovoy and David Abrahams
177 Distributed under the Boost Software License, Version 1.0. (See accompanying
178 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)