comparison DEPENDENCIES/generic/include/boost/fusion/container/map/detail/map_impl.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
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/detail/access.hpp>
11 #include <boost/fusion/iterator/deref.hpp>
12 #include <boost/fusion/iterator/next.hpp>
13 #include <boost/mpl/int.hpp>
14 #include <boost/mpl/identity.hpp>
15
16 namespace boost { namespace fusion
17 {
18 struct fusion_sequence_tag;
19 }}
20
21 namespace boost { namespace fusion { namespace detail
22 {
23 struct map_impl_from_iterator {};
24
25 template <int index, typename ...T>
26 struct map_impl;
27
28 template <int index_>
29 struct map_impl<index_>
30 {
31 typedef fusion_sequence_tag tag;
32 static int const index = index_;
33 static int const size = 0;
34
35 map_impl() {}
36
37 template <typename Iterator>
38 map_impl(Iterator const& iter, map_impl_from_iterator)
39 {}
40
41 template <typename Iterator>
42 void assign(Iterator const& iter, map_impl_from_iterator)
43 {}
44
45 void get();
46 void get_val();
47 void get_key();
48 };
49
50 template <int index_, typename Pair, typename ...T>
51 struct map_impl<index_, Pair, T...> : map_impl<index_ + 1, T...>
52 {
53 typedef fusion_sequence_tag tag;
54 typedef map_impl<index_+1, T...> rest_type;
55
56 using rest_type::get;
57 using rest_type::get_val;
58 using rest_type::get_key;
59
60 static int const index = index_;
61 static int const size = rest_type::size + 1;
62
63 typedef Pair pair_type;
64 typedef typename Pair::first_type key_type;
65 typedef typename Pair::second_type value_type;
66
67 map_impl()
68 : rest_type(), element()
69 {}
70
71 map_impl(map_impl const& rhs)
72 : rest_type(rhs.get_base()), element(rhs.element)
73 {}
74
75 map_impl(map_impl&& rhs)
76 : rest_type(std::forward<rest_type>(*static_cast<rest_type*>(this)))
77 , element(std::forward<Pair>(rhs.element))
78 {}
79
80 template <typename ...U>
81 map_impl(map_impl<index, U...> const& rhs)
82 : rest_type(rhs.get_base()), element(rhs.element)
83 {}
84
85 map_impl(typename detail::call_param<Pair>::type element
86 , typename detail::call_param<T>::type... rest)
87 : rest_type(rest...), element(element)
88 {}
89
90 map_impl(Pair&& element, T&&... rest)
91 : rest_type(std::forward<T>(rest)...)
92 , element(std::forward<Pair>(element))
93 {}
94
95 template <typename Iterator>
96 map_impl(Iterator const& iter, map_impl_from_iterator fi)
97 : rest_type(fusion::next(iter), fi)
98 , element(*iter)
99 {}
100
101 rest_type& get_base()
102 {
103 return *this;
104 }
105
106 rest_type const& get_base() const
107 {
108 return *this;
109 }
110
111 value_type get_val(mpl::identity<key_type>);
112 pair_type get_val(mpl::int_<index>);
113 value_type get_val(mpl::identity<key_type>) const;
114 pair_type get_val(mpl::int_<index>) const;
115
116 key_type get_key(mpl::int_<index>);
117 key_type get_key(mpl::int_<index>) const;
118
119 typename cref_result<value_type>::type
120 get(mpl::identity<key_type>) const
121 {
122 return element.second;
123 }
124
125 typename ref_result<value_type>::type
126 get(mpl::identity<key_type>)
127 {
128 return element.second;
129 }
130
131 typename cref_result<pair_type>::type
132 get(mpl::int_<index>) const
133 {
134 return element;
135 }
136
137 typename ref_result<pair_type>::type
138 get(mpl::int_<index>)
139 {
140 return element;
141 }
142
143 template <typename ...U>
144 map_impl& operator=(map_impl<index, U...> const& rhs)
145 {
146 rest_type::operator=(rhs);
147 element = rhs.element;
148 return *this;
149 }
150
151 map_impl& operator=(map_impl const& rhs)
152 {
153 rest_type::operator=(rhs);
154 element = rhs.element;
155 return *this;
156 }
157
158 map_impl& operator=(map_impl&& rhs)
159 {
160 rest_type::operator=(std::forward<map_impl>(rhs));
161 element = std::forward<Pair>(rhs.element);
162 return *this;
163 }
164
165 template <typename Iterator>
166 void assign(Iterator const& iter, map_impl_from_iterator fi)
167 {
168 rest_type::assign(fusion::next(iter), fi);
169 element = *iter;
170 }
171
172 Pair element;
173 };
174 }}}
175
176 #endif