1 /*=============================================================================
2 Copyright (c) 2005-2013 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(BOOST_FUSION_MAP_IMPL_02032013_2233)
8 #define BOOST_FUSION_MAP_IMPL_02032013_2233
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>
17 namespace boost { namespace fusion
19 struct fusion_sequence_tag;
22 namespace boost { namespace fusion { namespace detail
24 struct map_impl_from_iterator {};
26 template <int index, typename ...T>
30 struct map_impl<index_>
32 typedef fusion_sequence_tag tag;
33 static int const index = index_;
34 static int const size = 0;
36 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
37 map_impl() BOOST_NOEXCEPT {}
39 template <typename Iterator>
40 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
41 map_impl(Iterator const&, map_impl_from_iterator) BOOST_NOEXCEPT
44 template <typename Iterator>
45 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
46 void assign(Iterator const&, map_impl_from_iterator) BOOST_NOEXCEPT
49 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
51 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
53 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
57 template <int index_, typename Pair, typename ...T>
58 struct map_impl<index_, Pair, T...> : map_impl<index_ + 1, T...>
60 typedef fusion_sequence_tag tag;
61 typedef map_impl<index_+1, T...> rest_type;
64 using rest_type::get_val;
65 using rest_type::get_key;
67 static int const index = index_;
68 static int const size = rest_type::size + 1;
70 typedef Pair pair_type;
71 typedef typename Pair::first_type key_type;
72 typedef typename Pair::second_type value_type;
74 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
76 : rest_type(), element()
79 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
80 map_impl(map_impl const& rhs)
81 : rest_type(rhs.get_base()), element(rhs.element)
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))
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)
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_)
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_))
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)
115 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
116 rest_type& get_base()
121 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
122 rest_type const& get_base() const
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;
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;
141 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
142 typename cref_result<value_type>::type
143 get(mpl::identity<key_type>) const
145 return element.second;
148 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
149 typename ref_result<value_type>::type
150 get(mpl::identity<key_type>)
152 return element.second;
155 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
156 typename cref_result<pair_type>::type
157 get(mpl::int_<index>) const
162 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
163 typename ref_result<pair_type>::type
164 get(mpl::int_<index>)
169 template <typename ...U>
170 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
171 map_impl& operator=(map_impl<index, U...> const& rhs)
173 rest_type::operator=(rhs);
174 element = rhs.element;
178 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
179 map_impl& operator=(map_impl const& rhs)
181 rest_type::operator=(rhs);
182 element = rhs.element;
186 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
187 map_impl& operator=(map_impl&& rhs)
189 rest_type::operator=(std::forward<map_impl>(rhs));
190 element = BOOST_FUSION_FWD_ELEM(Pair, rhs.element);
194 template <typename Iterator>
195 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
196 void assign(Iterator const& iter, map_impl_from_iterator fi)
198 rest_type::assign(fusion::next(iter), fi);