Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2001-2011 Joel de Guzman
|
Chris@16
|
3
|
Chris@16
|
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@16
|
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 ==============================================================================*/
|
Chris@16
|
7 #if !defined(FUSION_AT_05042005_0722)
|
Chris@16
|
8 #define FUSION_AT_05042005_0722
|
Chris@16
|
9
|
Chris@101
|
10 #include <boost/fusion/support/config.hpp>
|
Chris@16
|
11 #include <boost/mpl/int.hpp>
|
Chris@101
|
12 #include <boost/mpl/if.hpp>
|
Chris@101
|
13 #include <boost/mpl/less.hpp>
|
Chris@101
|
14 #include <boost/mpl/empty_base.hpp>
|
Chris@16
|
15 #include <boost/type_traits/is_const.hpp>
|
Chris@16
|
16 #include <boost/fusion/sequence/intrinsic_fwd.hpp>
|
Chris@16
|
17 #include <boost/fusion/support/tag_of.hpp>
|
Chris@16
|
18 #include <boost/fusion/support/detail/access.hpp>
|
Chris@16
|
19
|
Chris@16
|
20 namespace boost { namespace fusion
|
Chris@16
|
21 {
|
Chris@16
|
22 // Special tags:
|
Chris@16
|
23 struct sequence_facade_tag;
|
Chris@16
|
24 struct boost_tuple_tag; // boost::tuples::tuple tag
|
Chris@16
|
25 struct boost_array_tag; // boost::array tag
|
Chris@16
|
26 struct mpl_sequence_tag; // mpl sequence tag
|
Chris@16
|
27 struct std_pair_tag; // std::pair tag
|
Chris@16
|
28 struct std_tuple_tag; // std::tuple tag
|
Chris@16
|
29
|
Chris@16
|
30 namespace extension
|
Chris@16
|
31 {
|
Chris@16
|
32 template <typename Tag>
|
Chris@16
|
33 struct at_impl
|
Chris@16
|
34 {
|
Chris@16
|
35 template <typename Sequence, typename N>
|
Chris@16
|
36 struct apply;
|
Chris@16
|
37 };
|
Chris@16
|
38
|
Chris@16
|
39 template <>
|
Chris@16
|
40 struct at_impl<sequence_facade_tag>
|
Chris@16
|
41 {
|
Chris@16
|
42 template <typename Sequence, typename N>
|
Chris@16
|
43 struct apply : Sequence::template at<Sequence, N> {};
|
Chris@16
|
44 };
|
Chris@16
|
45
|
Chris@16
|
46 template <>
|
Chris@16
|
47 struct at_impl<boost_tuple_tag>;
|
Chris@16
|
48
|
Chris@16
|
49 template <>
|
Chris@16
|
50 struct at_impl<boost_array_tag>;
|
Chris@16
|
51
|
Chris@16
|
52 template <>
|
Chris@16
|
53 struct at_impl<mpl_sequence_tag>;
|
Chris@16
|
54
|
Chris@16
|
55 template <>
|
Chris@16
|
56 struct at_impl<std_pair_tag>;
|
Chris@16
|
57
|
Chris@16
|
58 template <>
|
Chris@16
|
59 struct at_impl<std_tuple_tag>;
|
Chris@16
|
60 }
|
Chris@16
|
61
|
Chris@101
|
62 namespace detail
|
Chris@101
|
63 {
|
Chris@101
|
64 template <typename Sequence, typename N, typename Tag>
|
Chris@101
|
65 struct at_impl
|
Chris@101
|
66 : mpl::if_<
|
Chris@101
|
67 mpl::less<N, typename extension::size_impl<Tag>::template apply<Sequence>::type>
|
Chris@101
|
68 , typename extension::at_impl<Tag>::template apply<Sequence, N>
|
Chris@101
|
69 , mpl::empty_base
|
Chris@101
|
70 >::type
|
Chris@101
|
71 {};
|
Chris@101
|
72 }
|
Chris@101
|
73
|
Chris@16
|
74 namespace result_of
|
Chris@16
|
75 {
|
Chris@16
|
76 template <typename Sequence, typename N>
|
Chris@16
|
77 struct at
|
Chris@101
|
78 : detail::at_impl<Sequence, N, typename detail::tag_of<Sequence>::type>
|
Chris@16
|
79 {};
|
Chris@16
|
80
|
Chris@16
|
81 template <typename Sequence, int N>
|
Chris@16
|
82 struct at_c
|
Chris@16
|
83 : at<Sequence, mpl::int_<N> >
|
Chris@16
|
84 {};
|
Chris@16
|
85 }
|
Chris@16
|
86
|
Chris@16
|
87
|
Chris@16
|
88 template <typename N, typename Sequence>
|
Chris@101
|
89 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
90 inline typename
|
Chris@16
|
91 lazy_disable_if<
|
Chris@16
|
92 is_const<Sequence>
|
Chris@16
|
93 , result_of::at<Sequence, N>
|
Chris@16
|
94 >::type
|
Chris@16
|
95 at(Sequence& seq)
|
Chris@16
|
96 {
|
Chris@16
|
97 return result_of::at<Sequence, N>::call(seq);
|
Chris@16
|
98 }
|
Chris@16
|
99
|
Chris@16
|
100 template <typename N, typename Sequence>
|
Chris@101
|
101 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
102 inline typename result_of::at<Sequence const, N>::type
|
Chris@16
|
103 at(Sequence const& seq)
|
Chris@16
|
104 {
|
Chris@16
|
105 return result_of::at<Sequence const, N>::call(seq);
|
Chris@16
|
106 }
|
Chris@16
|
107
|
Chris@16
|
108 template <int N, typename Sequence>
|
Chris@101
|
109 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
110 inline typename
|
Chris@16
|
111 lazy_disable_if<
|
Chris@16
|
112 is_const<Sequence>
|
Chris@16
|
113 , result_of::at_c<Sequence, N>
|
Chris@16
|
114 >::type
|
Chris@16
|
115 at_c(Sequence& seq)
|
Chris@16
|
116 {
|
Chris@16
|
117 return fusion::at<mpl::int_<N> >(seq);
|
Chris@16
|
118 }
|
Chris@16
|
119
|
Chris@16
|
120 template <int N, typename Sequence>
|
Chris@101
|
121 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
122 inline typename result_of::at_c<Sequence const, N>::type
|
Chris@16
|
123 at_c(Sequence const& seq)
|
Chris@16
|
124 {
|
Chris@16
|
125 return fusion::at<mpl::int_<N> >(seq);
|
Chris@16
|
126 }
|
Chris@16
|
127 }}
|
Chris@16
|
128
|
Chris@16
|
129 #endif
|
Chris@16
|
130
|