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