Chris@16
|
1 /*=============================================================================
|
Chris@16
|
2 Copyright (c) 2005-2013 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(BOOST_FUSION_MAP_IMPL_02032013_2233)
|
Chris@16
|
8 #define BOOST_FUSION_MAP_IMPL_02032013_2233
|
Chris@16
|
9
|
Chris@101
|
10 #include <boost/fusion/support/config.hpp>
|
Chris@16
|
11 #include <boost/fusion/support/detail/access.hpp>
|
Chris@16
|
12 #include <boost/fusion/iterator/deref.hpp>
|
Chris@16
|
13 #include <boost/fusion/iterator/next.hpp>
|
Chris@16
|
14 #include <boost/mpl/int.hpp>
|
Chris@16
|
15 #include <boost/mpl/identity.hpp>
|
Chris@16
|
16
|
Chris@16
|
17 namespace boost { namespace fusion
|
Chris@16
|
18 {
|
Chris@16
|
19 struct fusion_sequence_tag;
|
Chris@16
|
20 }}
|
Chris@16
|
21
|
Chris@16
|
22 namespace boost { namespace fusion { namespace detail
|
Chris@16
|
23 {
|
Chris@16
|
24 struct map_impl_from_iterator {};
|
Chris@16
|
25
|
Chris@16
|
26 template <int index, typename ...T>
|
Chris@16
|
27 struct map_impl;
|
Chris@16
|
28
|
Chris@16
|
29 template <int index_>
|
Chris@16
|
30 struct map_impl<index_>
|
Chris@16
|
31 {
|
Chris@16
|
32 typedef fusion_sequence_tag tag;
|
Chris@16
|
33 static int const index = index_;
|
Chris@16
|
34 static int const size = 0;
|
Chris@16
|
35
|
Chris@101
|
36 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
37 map_impl() BOOST_NOEXCEPT {}
|
Chris@16
|
38
|
Chris@16
|
39 template <typename Iterator>
|
Chris@101
|
40 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
41 map_impl(Iterator const&, map_impl_from_iterator) BOOST_NOEXCEPT
|
Chris@16
|
42 {}
|
Chris@16
|
43
|
Chris@16
|
44 template <typename Iterator>
|
Chris@101
|
45 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
46 void assign(Iterator const&, map_impl_from_iterator) BOOST_NOEXCEPT
|
Chris@16
|
47 {}
|
Chris@16
|
48
|
Chris@101
|
49 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
50 void get();
|
Chris@101
|
51 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
52 void get_val();
|
Chris@101
|
53 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
54 void get_key();
|
Chris@16
|
55 };
|
Chris@16
|
56
|
Chris@16
|
57 template <int index_, typename Pair, typename ...T>
|
Chris@16
|
58 struct map_impl<index_, Pair, T...> : map_impl<index_ + 1, T...>
|
Chris@16
|
59 {
|
Chris@16
|
60 typedef fusion_sequence_tag tag;
|
Chris@16
|
61 typedef map_impl<index_+1, T...> rest_type;
|
Chris@16
|
62
|
Chris@16
|
63 using rest_type::get;
|
Chris@16
|
64 using rest_type::get_val;
|
Chris@16
|
65 using rest_type::get_key;
|
Chris@16
|
66
|
Chris@16
|
67 static int const index = index_;
|
Chris@16
|
68 static int const size = rest_type::size + 1;
|
Chris@16
|
69
|
Chris@16
|
70 typedef Pair pair_type;
|
Chris@16
|
71 typedef typename Pair::first_type key_type;
|
Chris@16
|
72 typedef typename Pair::second_type value_type;
|
Chris@16
|
73
|
Chris@101
|
74 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
75 map_impl()
|
Chris@16
|
76 : rest_type(), element()
|
Chris@16
|
77 {}
|
Chris@16
|
78
|
Chris@101
|
79 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
80 map_impl(map_impl const& rhs)
|
Chris@16
|
81 : rest_type(rhs.get_base()), element(rhs.element)
|
Chris@16
|
82 {}
|
Chris@16
|
83
|
Chris@101
|
84 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
85 map_impl(map_impl&& rhs)
|
Chris@101
|
86 : rest_type(BOOST_FUSION_FWD_ELEM(rest_type, *static_cast<rest_type*>(&rhs)))
|
Chris@101
|
87 , element(BOOST_FUSION_FWD_ELEM(Pair, rhs.element))
|
Chris@16
|
88 {}
|
Chris@16
|
89
|
Chris@16
|
90 template <typename ...U>
|
Chris@101
|
91 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
92 map_impl(map_impl<index, U...> const& rhs)
|
Chris@16
|
93 : rest_type(rhs.get_base()), element(rhs.element)
|
Chris@16
|
94 {}
|
Chris@16
|
95
|
Chris@101
|
96 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
97 map_impl(typename detail::call_param<Pair>::type element_
|
Chris@16
|
98 , typename detail::call_param<T>::type... rest)
|
Chris@101
|
99 : rest_type(rest...), element(element_)
|
Chris@16
|
100 {}
|
Chris@16
|
101
|
Chris@101
|
102 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
103 map_impl(Pair&& element_, T&&... rest)
|
Chris@101
|
104 : rest_type(BOOST_FUSION_FWD_ELEM(T, rest)...)
|
Chris@101
|
105 , element(BOOST_FUSION_FWD_ELEM(Pair, element_))
|
Chris@16
|
106 {}
|
Chris@16
|
107
|
Chris@16
|
108 template <typename Iterator>
|
Chris@101
|
109 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
110 map_impl(Iterator const& iter, map_impl_from_iterator fi)
|
Chris@16
|
111 : rest_type(fusion::next(iter), fi)
|
Chris@16
|
112 , element(*iter)
|
Chris@16
|
113 {}
|
Chris@16
|
114
|
Chris@101
|
115 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
116 rest_type& get_base()
|
Chris@16
|
117 {
|
Chris@16
|
118 return *this;
|
Chris@16
|
119 }
|
Chris@16
|
120
|
Chris@101
|
121 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
122 rest_type const& get_base() const
|
Chris@16
|
123 {
|
Chris@16
|
124 return *this;
|
Chris@16
|
125 }
|
Chris@16
|
126
|
Chris@101
|
127 BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
128 value_type get_val(mpl::identity<key_type>);
|
Chris@101
|
129 BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
130 pair_type get_val(mpl::int_<index>);
|
Chris@101
|
131 BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
132 value_type get_val(mpl::identity<key_type>) const;
|
Chris@101
|
133 BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
134 pair_type get_val(mpl::int_<index>) const;
|
Chris@16
|
135
|
Chris@101
|
136 BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
137 mpl::identity<key_type> get_key(mpl::int_<index>);
|
Chris@101
|
138 BOOST_FUSION_GPU_ENABLED
|
Chris@101
|
139 mpl::identity<key_type> get_key(mpl::int_<index>) const;
|
Chris@16
|
140
|
Chris@101
|
141 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
142 typename cref_result<value_type>::type
|
Chris@16
|
143 get(mpl::identity<key_type>) const
|
Chris@16
|
144 {
|
Chris@16
|
145 return element.second;
|
Chris@16
|
146 }
|
Chris@16
|
147
|
Chris@101
|
148 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
149 typename ref_result<value_type>::type
|
Chris@16
|
150 get(mpl::identity<key_type>)
|
Chris@16
|
151 {
|
Chris@16
|
152 return element.second;
|
Chris@16
|
153 }
|
Chris@16
|
154
|
Chris@101
|
155 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
156 typename cref_result<pair_type>::type
|
Chris@16
|
157 get(mpl::int_<index>) const
|
Chris@16
|
158 {
|
Chris@16
|
159 return element;
|
Chris@16
|
160 }
|
Chris@16
|
161
|
Chris@101
|
162 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
163 typename ref_result<pair_type>::type
|
Chris@16
|
164 get(mpl::int_<index>)
|
Chris@16
|
165 {
|
Chris@16
|
166 return element;
|
Chris@16
|
167 }
|
Chris@16
|
168
|
Chris@16
|
169 template <typename ...U>
|
Chris@101
|
170 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
171 map_impl& operator=(map_impl<index, U...> const& rhs)
|
Chris@16
|
172 {
|
Chris@16
|
173 rest_type::operator=(rhs);
|
Chris@16
|
174 element = rhs.element;
|
Chris@16
|
175 return *this;
|
Chris@16
|
176 }
|
Chris@16
|
177
|
Chris@101
|
178 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
179 map_impl& operator=(map_impl const& rhs)
|
Chris@16
|
180 {
|
Chris@16
|
181 rest_type::operator=(rhs);
|
Chris@16
|
182 element = rhs.element;
|
Chris@16
|
183 return *this;
|
Chris@16
|
184 }
|
Chris@16
|
185
|
Chris@101
|
186 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
187 map_impl& operator=(map_impl&& rhs)
|
Chris@16
|
188 {
|
Chris@16
|
189 rest_type::operator=(std::forward<map_impl>(rhs));
|
Chris@101
|
190 element = BOOST_FUSION_FWD_ELEM(Pair, rhs.element);
|
Chris@16
|
191 return *this;
|
Chris@16
|
192 }
|
Chris@16
|
193
|
Chris@16
|
194 template <typename Iterator>
|
Chris@101
|
195 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
|
Chris@16
|
196 void assign(Iterator const& iter, map_impl_from_iterator fi)
|
Chris@16
|
197 {
|
Chris@16
|
198 rest_type::assign(fusion::next(iter), fi);
|
Chris@16
|
199 element = *iter;
|
Chris@16
|
200 }
|
Chris@16
|
201
|
Chris@16
|
202 Pair element;
|
Chris@16
|
203 };
|
Chris@16
|
204 }}}
|
Chris@16
|
205
|
Chris@16
|
206 #endif
|