首页 / 序列 / 内置元函数 / at |
template< typename Sequence , typename N > struct at { typedef unspecified type; }; template< typename AssocSeq , typename Key , typename Default = unspecified > struct at { typedef unspecified type; };
#include <boost/mpl/at.hpp>
Parameter | 要求 | 描述 |
---|---|---|
序列 | Forward Sequence | 要检查的序列。 |
AssocSeq | 关联序列 | 要检查的序列。 |
N | 整数常量 | 从序列开头算起的偏移量,指定要检索的元素。 |
键 | 任何类型 | 要检索的元素的键。 |
Default | 任何类型 | 如果找不到元素,则返回的默认值。 |
对于任何 Forward Sequences,以及 Integral Constantn:
typedef at<s,n>::type t;
返回类型 | 一个类型。 |
---|---|
前置条件 | 0 <= n::value < size<s>::value. |
语义 | 等同于 typedef deref< advance< begin<s>::type,n >::type >::type t; |
序列原型 | 复杂度 |
---|---|
Forward Sequence | 线性。 |
随机访问序列 | 摊销常数时间。 |
关联序列 | 摊销常数时间。 |
typedef range_c<long,10,50> 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<s,char>::type, void_ > )); BOOST_MPL_ASSERT(( is_same< at<s,int>::type, int > ));