1.. Sequences/Intrinsic Metafunctions//at 2 3at 4== 5 6Synopsis 7-------- 8 9.. parsed-literal:: 10 11 template< 12 typename Sequence 13 , typename N 14 > 15 struct at 16 { 17 typedef |unspecified| type; 18 }; 19 20 template< 21 typename AssocSeq 22 , typename Key 23 , typename Default = |unspecified| 24 > 25 struct at 26 { 27 typedef |unspecified| type; 28 }; 29 30 31Description 32----------- 33 34``at`` is an |overloaded name|: 35 36* ``at<Sequence,N>`` returns the ``N``-th element from the beginning of the 37 |Forward Sequence| ``Sequence``. 38 39* ``at<AssocSeq,Key,Default>`` returns the first element associated with ``Key`` 40 in the |Associative Sequence| ``AssocSeq``, or ``Default`` if no such element 41 exists. 42 43 44Header 45------ 46 47.. parsed-literal:: 48 49 #include <boost/mpl/at.hpp> 50 51 52Model of 53-------- 54 55|Tag Dispatched Metafunction| 56 57 58Parameters 59---------- 60 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 | 74| | | not found. | 75+---------------+---------------------------+-----------------------------------------------+ 76 77 78Expression semantics 79-------------------- 80 81.. compound:: 82 :class: expression-semantics 83 84 For any |Forward Sequence| ``s``, and |Integral Constant| ``n``: 85 86 .. parsed-literal:: 87 88 typedef at<s,n>::type t; 89 90 :Return type: 91 A type. 92 93 :Precondition: 94 ``0 <= n::value < size<s>::value``. 95 96 :Semantics: 97 Equivalent to 98 99 .. parsed-literal:: 100 101 typedef deref< advance< begin<s>::type,n >::type >::type t; 102 103 104.. compound:: 105 :class: expression-semantics 106 107 For any |Associative Sequence| ``s``, and arbitrary types ``key`` and ``x``: 108 109 .. parsed-literal:: 110 111 typedef at<s,key,x>::type t; 112 113 :Return type: 114 A type. 115 116 :Semantics: 117 If ``has_key<s,key>::value == true``, ``t`` is the value type associated with ``key``; 118 otherwise ``t`` is identical to ``x``. 119 120 121 .. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 122 123 .. parsed-literal:: 124 125 typedef at<s,key>::type t; 126 127 :Return type: 128 A type. 129 130 :Semantics: 131 Equivalent to 132 133 .. parsed-literal:: 134 135 typedef at<s,key,void\_>::type t; 136 137 138Complexity 139---------- 140 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+-------------------------------+-----------------------------------+ 150 151Example 152------- 153 154.. parsed-literal:: 155 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 ); 160 161 162.. parsed-literal:: 163 164 typedef set< int const,long*,double > s; 165 166 BOOST_MPL_ASSERT(( is_same< at<s,char>::type, void\_ > )); 167 BOOST_MPL_ASSERT(( is_same< at<s,int>::type, int > )); 168 169 170See also 171-------- 172 173|Forward Sequence|, |Random Access Sequence|, |Associative Sequence|, |at_c|, |front|, |back| 174 175 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) 179