]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/fusion/container/vector/vector.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / fusion / container / vector / vector.hpp
1 /*=============================================================================
2 Copyright (c) 2014-2015 Kohei Takahashi
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 #ifndef FUSION_VECTOR_11052014_1625
8 #define FUSION_VECTOR_11052014_1625
9
10 #include <boost/config.hpp>
11 #include <boost/fusion/support/config.hpp>
12 #include <boost/fusion/container/vector/detail/config.hpp>
13 #include <boost/fusion/container/vector/vector_fwd.hpp>
14
15 ///////////////////////////////////////////////////////////////////////////////
16 // Without variadics, we will use the PP version
17 ///////////////////////////////////////////////////////////////////////////////
18 #if !defined(BOOST_FUSION_HAS_VARIADIC_VECTOR)
19 # include <boost/fusion/container/vector/detail/cpp03/vector.hpp>
20 #else
21
22 ///////////////////////////////////////////////////////////////////////////////
23 // C++11 interface
24 ///////////////////////////////////////////////////////////////////////////////
25 #include <boost/fusion/support/sequence_base.hpp>
26 #include <boost/fusion/support/is_sequence.hpp>
27 #include <boost/fusion/support/detail/and.hpp>
28 #include <boost/fusion/support/detail/index_sequence.hpp>
29 #include <boost/fusion/container/vector/detail/at_impl.hpp>
30 #include <boost/fusion/container/vector/detail/value_at_impl.hpp>
31 #include <boost/fusion/container/vector/detail/begin_impl.hpp>
32 #include <boost/fusion/container/vector/detail/end_impl.hpp>
33 #include <boost/fusion/sequence/intrinsic/begin.hpp>
34 #include <boost/fusion/sequence/intrinsic/size.hpp>
35 #include <boost/fusion/iterator/advance.hpp>
36 #include <boost/fusion/iterator/deref.hpp>
37 #include <boost/core/enable_if.hpp>
38 #include <boost/mpl/int.hpp>
39 #include <boost/type_traits/integral_constant.hpp>
40 #include <boost/type_traits/is_base_of.hpp>
41 #include <boost/type_traits/is_convertible.hpp>
42 #include <boost/type_traits/remove_reference.hpp>
43 #include <cstddef>
44 #include <utility>
45
46 namespace boost { namespace fusion
47 {
48 struct vector_tag;
49 struct random_access_traversal_tag;
50
51 namespace vector_detail
52 {
53 struct each_elem {};
54
55 template <
56 typename This, typename T, typename T_, std::size_t Size, bool IsSeq
57 >
58 struct can_convert_impl : false_type {};
59
60 template <typename This, typename T, typename Sequence, std::size_t Size>
61 struct can_convert_impl<This, T, Sequence, Size, true> : true_type {};
62
63 template <typename This, typename Sequence, typename T>
64 struct can_convert_impl<This, Sequence, T, 1, true>
65 : integral_constant<
66 bool
67 , !is_convertible<
68 Sequence
69 , typename fusion::extension::value_at_impl<vector_tag>::
70 template apply< This, mpl::int_<0> >::type
71 >::value
72 >
73 {};
74
75 template <typename This, typename T, typename T_, std::size_t Size>
76 struct can_convert
77 : can_convert_impl<
78 This, T, T_, Size, traits::is_sequence<T_>::value
79 >
80 {};
81
82 template <typename T, bool IsSeq, std::size_t Size>
83 struct is_longer_sequence_impl : false_type {};
84
85 template <typename Sequence, std::size_t Size>
86 struct is_longer_sequence_impl<Sequence, true, Size>
87 : integral_constant<
88 bool, (fusion::result_of::size<Sequence>::value >= Size)
89 >
90 {};
91
92 template<typename T, std::size_t Size>
93 struct is_longer_sequence
94 : is_longer_sequence_impl<T, traits::is_sequence<T>::value, Size>
95 {};
96
97 // forward_at_c allows to access Nth element even if ForwardSequence
98 // since fusion::at_c requires RandomAccessSequence.
99 namespace result_of
100 {
101 template <typename Sequence, int N>
102 struct forward_at_c
103 : fusion::result_of::deref<
104 typename fusion::result_of::advance_c<
105 typename fusion::result_of::begin<
106 typename remove_reference<Sequence>::type
107 >::type
108 , N
109 >::type
110 >
111 {};
112 }
113
114 template <int N, typename Sequence>
115 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
116 inline typename result_of::forward_at_c<Sequence, N>::type
117 forward_at_c(Sequence&& seq)
118 {
119 typedef typename
120 result_of::forward_at_c<Sequence, N>::type
121 result;
122 return std::forward<result>(*advance_c<N>(begin(seq)));
123 }
124
125 // Object proxy since preserve object order
126 template <std::size_t, typename T>
127 struct store
128 {
129 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
130 store()
131 : elem() // value-initialized explicitly
132 {}
133
134 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
135 store(store const& rhs)
136 : elem(rhs.elem)
137 {}
138
139 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
140 store&
141 operator=(store const& rhs)
142 {
143 elem = rhs.elem;
144 return *this;
145 }
146
147 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
148 store(store&& rhs)
149 : elem(static_cast<T&&>(rhs.elem))
150 {}
151
152 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
153 store&
154 operator=(store&& rhs)
155 {
156 elem = static_cast<T&&>(rhs.elem);
157 return *this;
158 }
159
160 template <
161 typename U
162 , typename = typename boost::disable_if<
163 is_base_of<store, typename remove_reference<U>::type>
164 >::type
165 >
166 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
167 store(U&& rhs)
168 : elem(std::forward<U>(rhs))
169 {}
170
171 T elem;
172 };
173
174 template <typename I, typename ...T>
175 struct vector_data;
176
177 template <std::size_t ...I, typename ...T>
178 struct vector_data<detail::index_sequence<I...>, T...>
179 : store<I, T>...
180 , sequence_base<vector_data<detail::index_sequence<I...>, T...> >
181 {
182 typedef vector_tag fusion_tag;
183 typedef fusion_sequence_tag tag; // this gets picked up by MPL
184 typedef mpl::false_ is_view;
185 typedef random_access_traversal_tag category;
186 typedef mpl::int_<sizeof...(T)> size;
187 typedef vector<T...> type_sequence;
188
189 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
190 BOOST_DEFAULTED_FUNCTION(vector_data(), {})
191
192 template <
193 typename Sequence
194 , typename Sequence_ = typename remove_reference<Sequence>::type
195 , typename = typename boost::enable_if<
196 can_convert<vector_data, Sequence, Sequence_, sizeof...(I)>
197 >::type
198 >
199 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
200 explicit
201 vector_data(each_elem, Sequence&& rhs)
202 : store<I, T>(forward_at_c<I>(std::forward<Sequence>(rhs)))...
203 {}
204
205 template <typename ...U>
206 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
207 explicit
208 vector_data(each_elem, U&&... var)
209 : store<I, T>(std::forward<U>(var))...
210 {}
211
212 template <typename Sequence>
213 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
214 void
215 assign_sequence(Sequence&& seq)
216 {
217 assign(std::forward<Sequence>(seq), detail::index_sequence<I...>());
218 }
219
220 template <typename Sequence>
221 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
222 void
223 assign(Sequence&&, detail::index_sequence<>) {}
224
225 template <typename Sequence, std::size_t N, std::size_t ...M>
226 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
227 void
228 assign(Sequence&& seq, detail::index_sequence<N, M...>)
229 {
230 at_impl(mpl::int_<N>()) = vector_detail::forward_at_c<N>(seq);
231 assign(std::forward<Sequence>(seq), detail::index_sequence<M...>());
232 }
233
234 template <std::size_t N, typename U>
235 static BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
236 U& at_detail(store<N, U>* this_)
237 {
238 return this_->elem;
239 }
240
241 template <std::size_t N, typename U>
242 static BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
243 U const& at_detail(store<N, U> const* this_)
244 {
245 return this_->elem;
246 }
247
248 template <typename J>
249 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
250 auto at_impl(J) -> decltype(at_detail<J::value>(this))
251 {
252 return at_detail<J::value>(this);
253 }
254
255 template <typename J>
256 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
257 auto at_impl(J) const -> decltype(at_detail<J::value>(this))
258 {
259 return at_detail<J::value>(this);
260 }
261 };
262 } // namespace boost::fusion::vector_detail
263
264 template <typename... T>
265 struct vector
266 : vector_detail::vector_data<
267 typename detail::make_index_sequence<sizeof...(T)>::type
268 , T...
269 >
270 {
271 typedef vector_detail::vector_data<
272 typename detail::make_index_sequence<sizeof...(T)>::type
273 , T...
274 > base;
275
276 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
277 BOOST_DEFAULTED_FUNCTION(vector(), {})
278
279 template <
280 typename... U
281 , typename = typename boost::enable_if_c<(
282 sizeof...(U) >= 1 &&
283 fusion::detail::and_<is_convertible<U, T>...>::value &&
284 !fusion::detail::and_<
285 is_base_of<vector, typename remove_reference<U>::type>...
286 >::value
287 )>::type
288 >
289 // XXX: constexpr become error due to pull-request #79, booooo!!
290 // In the (near) future release, should be fixed.
291 /* BOOST_CONSTEXPR */ BOOST_FUSION_GPU_ENABLED
292 explicit vector(U&&... u)
293 : base(vector_detail::each_elem(), std::forward<U>(u)...)
294 {}
295
296 template <
297 typename Sequence
298 , typename = typename boost::enable_if_c<
299 vector_detail::is_longer_sequence<
300 typename remove_reference<Sequence>::type, sizeof...(T)
301 >::value
302 >::type
303 >
304 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
305 vector(Sequence&& seq)
306 : base(vector_detail::each_elem(), std::forward<Sequence>(seq))
307 {}
308
309 template <typename Sequence>
310 BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
311 vector&
312 operator=(Sequence&& rhs)
313 {
314 base::assign_sequence(std::forward<Sequence>(rhs));
315 return *this;
316 }
317 };
318 }}
319
320 #endif
321 #endif
322