fix doc example typo
[boost.git] / boost / fusion / container / list / detail / at_impl.hpp
blob4dee15dcda149c32b5c62b75263638002970938b
1 /*=============================================================================
2 Copyright (c) 2001-2006 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #if !defined(FUSION_AT_IMPL_07172005_0726)
8 #define FUSION_AT_IMPL_07172005_0726
10 #include <boost/fusion/support/detail/access.hpp>
11 #include <boost/type_traits/is_const.hpp>
12 #include <boost/type_traits/add_const.hpp>
13 #include <boost/mpl/eval_if.hpp>
14 #include <boost/mpl/bool.hpp>
16 namespace boost { namespace fusion
18 namespace detail
20 template <typename Cons>
21 struct cons_deref
23 typedef typename Cons::car_type type;
26 template <typename Cons, int I>
27 struct cons_advance
29 typedef typename
30 cons_advance<Cons, I-1>::type::cdr_type
31 type;
34 template <typename Cons>
35 struct cons_advance<Cons, 0>
37 typedef Cons type;
40 template <typename Cons>
41 struct cons_advance<Cons, 1>
43 typedef typename Cons::cdr_type type;
46 template <typename Cons>
47 struct cons_advance<Cons, 2>
49 #if BOOST_WORKAROUND(BOOST_MSVC, > 1400) // VC8 and above
50 typedef typename Cons::cdr_type::cdr_type type;
51 #else
52 typedef typename Cons::cdr_type _a;
53 typedef typename _a::cdr_type type;
54 #endif
57 template <typename Cons>
58 struct cons_advance<Cons, 3>
60 #if BOOST_WORKAROUND(BOOST_MSVC, > 1400) // VC8 and above
61 typedef typename Cons::cdr_type::cdr_type::cdr_type type;
62 #else
63 typedef typename Cons::cdr_type _a;
64 typedef typename _a::cdr_type _b;
65 typedef typename _b::cdr_type type;
66 #endif
69 template <typename Cons>
70 struct cons_advance<Cons, 4>
72 #if BOOST_WORKAROUND(BOOST_MSVC, > 1400) // VC8 and above
73 typedef typename Cons::cdr_type::cdr_type::cdr_type::cdr_type type;
74 #else
75 typedef typename Cons::cdr_type _a;
76 typedef typename _a::cdr_type _b;
77 typedef typename _b::cdr_type _c;
78 typedef typename _c::cdr_type type;
79 #endif
83 struct cons_tag;
85 namespace extension
87 template <typename Tag>
88 struct at_impl;
90 template <>
91 struct at_impl<cons_tag>
93 template <typename Sequence, typename N>
94 struct apply
96 typedef detail::cons_deref<
97 typename detail::cons_advance<Sequence, N::value>::type>
98 element;
100 typedef typename
101 mpl::eval_if<
102 is_const<Sequence>
103 , detail::cref_result<element>
104 , detail::ref_result<element>
105 >::type
106 type;
108 template <typename Cons, int N2>
109 static type
110 call(Cons& s, mpl::int_<N2>)
112 return call(s.cdr, mpl::int_<N2-1>());
115 template <typename Cons>
116 static type
117 call(Cons& s, mpl::int_<0>)
119 return s.car;
122 static type
123 call(Sequence& s)
125 return call(s, mpl::int_<N::value>());
132 #endif