comparison DEPENDENCIES/generic/include/boost/intrusive/detail/mpl.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
1 ///////////////////////////////////////////////////////////////////////////// 1 /////////////////////////////////////////////////////////////////////////////
2 // 2 //
3 // (C) Copyright Ion Gaztanaga 2006-2013 3 // (C) Copyright Ion Gaztanaga 2006-2014
4 // (C) Copyright Microsoft Corporation 2014
4 // 5 //
5 // Distributed under the Boost Software License, Version 1.0. 6 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at 7 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt) 8 // http://www.boost.org/LICENSE_1_0.txt)
8 // 9 //
11 ///////////////////////////////////////////////////////////////////////////// 12 /////////////////////////////////////////////////////////////////////////////
12 13
13 #ifndef BOOST_INTRUSIVE_DETAIL_MPL_HPP 14 #ifndef BOOST_INTRUSIVE_DETAIL_MPL_HPP
14 #define BOOST_INTRUSIVE_DETAIL_MPL_HPP 15 #define BOOST_INTRUSIVE_DETAIL_MPL_HPP
15 16
17 #ifndef BOOST_CONFIG_HPP
18 # include <boost/config.hpp>
19 #endif
20
21 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 # pragma once
23 #endif
24
16 #include <boost/intrusive/detail/config_begin.hpp> 25 #include <boost/intrusive/detail/config_begin.hpp>
17 #include <cstddef> 26 #include <cstddef>
18 27
19 namespace boost { 28 namespace boost {
20 namespace intrusive { 29 namespace intrusive {
21 namespace detail { 30 namespace detail {
22 31
32 template <typename T, typename U>
33 struct is_same
34 {
35 static const bool value = false;
36 };
37
38 template <typename T>
39 struct is_same<T, T>
40 {
41 static const bool value = true;
42 };
43
44 template<typename T>
45 struct add_const
46 { typedef const T type; };
47
48 template<typename T>
49 struct remove_const
50 { typedef T type; };
51
52 template<typename T>
53 struct remove_const<const T>
54 { typedef T type; };
55
56 template<typename T>
57 struct remove_cv
58 { typedef T type; };
59
60 template<typename T>
61 struct remove_cv<const T>
62 { typedef T type; };
63
64 template<typename T>
65 struct remove_cv<const volatile T>
66 { typedef T type; };
67
68 template<typename T>
69 struct remove_cv<volatile T>
70 { typedef T type; };
71
72 template<class T>
73 struct remove_reference
74 {
75 typedef T type;
76 };
77
78 template<class T>
79 struct remove_reference<T&>
80 {
81 typedef T type;
82 };
83
84 template<class T>
85 struct remove_pointer
86 {
87 typedef T type;
88 };
89
90 template<class T>
91 struct remove_pointer<T*>
92 {
93 typedef T type;
94 };
95
96 template<class T>
97 struct add_pointer
98 {
99 typedef T *type;
100 };
101
23 typedef char one; 102 typedef char one;
24 struct two {one _[2];}; 103 struct two {one _[2];};
25 104
26 template< bool C_ > 105 template< bool C_ >
27 struct bool_ 106 struct bool_
28 { 107 {
29 static const bool value = C_; 108 static const bool value = C_;
109 };
110
111 template< class Integer, Integer Value >
112 struct integer
113 {
114 static const Integer value = Value;
30 }; 115 };
31 116
32 typedef bool_<true> true_; 117 typedef bool_<true> true_;
33 typedef bool_<false> false_; 118 typedef bool_<false> false_;
34 119
56 struct apply 141 struct apply
57 { 142 {
58 typedef typename F::template apply<Param>::type type; 143 typedef typename F::template apply<Param>::type type;
59 }; 144 };
60 145
146 #if defined(_MSC_VER) && (_MSC_VER >= 1400)
147
148 template <class T, class U>
149 struct is_convertible
150 {
151 static const bool value = __is_convertible_to(T, U);
152 };
153
154 #else
155
61 template <class T, class U> 156 template <class T, class U>
62 class is_convertible 157 class is_convertible
63 { 158 {
64 typedef char true_t; 159 typedef char true_t;
65 class false_t { char dummy[2]; }; 160 class false_t { char dummy[2]; };
66 static true_t dispatch(U); 161 //use any_conversion as first parameter since in MSVC
162 //overaligned types can't go through ellipsis
67 static false_t dispatch(...); 163 static false_t dispatch(...);
68 static const T &trigger(); 164 static true_t dispatch(U);
165 static typename remove_reference<T>::type &trigger();
69 public: 166 public:
70 static const bool value = sizeof(dispatch(trigger())) == sizeof(true_t); 167 static const bool value = sizeof(dispatch(trigger())) == sizeof(true_t);
71 }; 168 };
169
170 #endif
72 171
73 template< 172 template<
74 bool C 173 bool C
75 , typename T1 174 , typename T1
76 , typename T2 175 , typename T2
122 struct identity 221 struct identity
123 { 222 {
124 typedef T type; 223 typedef T type;
125 }; 224 };
126 225
127 #if defined(BOOST_MSVC) || defined(__BORLANDC_) 226 template<class T, bool Add>
128 #define BOOST_INTRUSIVE_TT_DECL __cdecl 227 struct add_const_if_c
129 #else 228 {
130 #define BOOST_INTRUSIVE_TT_DECL 229 typedef typename if_c
131 #endif 230 < Add
132 231 , typename add_const<T>::type
133 #if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64) && !defined(UNDER_CE) 232 , T
134 #define BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS 233 >::type type;
135 #endif 234 };
136 235
137 template <typename T>
138 struct is_unary_or_binary_function_impl
139 { static const bool value = false; };
140
141 // see boost ticket #4094
142 // avoid duplicate definitions of is_unary_or_binary_function_impl
143 #ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
144
145 template <typename R>
146 struct is_unary_or_binary_function_impl<R (*)()>
147 { static const bool value = true; };
148
149 template <typename R>
150 struct is_unary_or_binary_function_impl<R (*)(...)>
151 { static const bool value = true; };
152
153 #else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
154
155 template <typename R>
156 struct is_unary_or_binary_function_impl<R (__stdcall*)()>
157 { static const bool value = true; };
158
159 #ifndef _MANAGED
160
161 template <typename R>
162 struct is_unary_or_binary_function_impl<R (__fastcall*)()>
163 { static const bool value = true; };
164
165 #endif
166
167 template <typename R>
168 struct is_unary_or_binary_function_impl<R (__cdecl*)()>
169 { static const bool value = true; };
170
171 template <typename R>
172 struct is_unary_or_binary_function_impl<R (__cdecl*)(...)>
173 { static const bool value = true; };
174
175 #endif
176
177 // see boost ticket #4094
178 // avoid duplicate definitions of is_unary_or_binary_function_impl
179 #ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
180
181 template <typename R, class T0>
182 struct is_unary_or_binary_function_impl<R (*)(T0)>
183 { static const bool value = true; };
184
185 template <typename R, class T0>
186 struct is_unary_or_binary_function_impl<R (*)(T0...)>
187 { static const bool value = true; };
188
189 #else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
190
191 template <typename R, class T0>
192 struct is_unary_or_binary_function_impl<R (__stdcall*)(T0)>
193 { static const bool value = true; };
194
195 #ifndef _MANAGED
196
197 template <typename R, class T0>
198 struct is_unary_or_binary_function_impl<R (__fastcall*)(T0)>
199 { static const bool value = true; };
200
201 #endif
202
203 template <typename R, class T0>
204 struct is_unary_or_binary_function_impl<R (__cdecl*)(T0)>
205 { static const bool value = true; };
206
207 template <typename R, class T0>
208 struct is_unary_or_binary_function_impl<R (__cdecl*)(T0...)>
209 { static const bool value = true; };
210
211 #endif
212
213 // see boost ticket #4094
214 // avoid duplicate definitions of is_unary_or_binary_function_impl
215 #ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
216
217 template <typename R, class T0, class T1>
218 struct is_unary_or_binary_function_impl<R (*)(T0, T1)>
219 { static const bool value = true; };
220
221 template <typename R, class T0, class T1>
222 struct is_unary_or_binary_function_impl<R (*)(T0, T1...)>
223 { static const bool value = true; };
224
225 #else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
226
227 template <typename R, class T0, class T1>
228 struct is_unary_or_binary_function_impl<R (__stdcall*)(T0, T1)>
229 { static const bool value = true; };
230
231 #ifndef _MANAGED
232
233 template <typename R, class T0, class T1>
234 struct is_unary_or_binary_function_impl<R (__fastcall*)(T0, T1)>
235 { static const bool value = true; };
236
237 #endif
238
239 template <typename R, class T0, class T1>
240 struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1)>
241 { static const bool value = true; };
242
243 template <typename R, class T0, class T1>
244 struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1...)>
245 { static const bool value = true; };
246 #endif
247
248 template <typename T>
249 struct is_unary_or_binary_function_impl<T&>
250 { static const bool value = false; };
251
252 template<typename T>
253 struct is_unary_or_binary_function
254 { static const bool value = is_unary_or_binary_function_impl<T>::value; };
255 236
256 //boost::alignment_of yields to 10K lines of preprocessed code, so we 237 //boost::alignment_of yields to 10K lines of preprocessed code, so we
257 //need an alternative 238 //need an alternative
258 template <typename T> struct alignment_of; 239 template <typename T> struct alignment_of;
259 240
276 { 257 {
277 static const std::size_t value = alignment_logic 258 static const std::size_t value = alignment_logic
278 < sizeof(alignment_of_hack<T>) - sizeof(T) 259 < sizeof(alignment_of_hack<T>) - sizeof(T)
279 , sizeof(T) 260 , sizeof(T)
280 >::value; 261 >::value;
281 };
282
283 template <typename T, typename U>
284 struct is_same
285 {
286 static const bool value = false;
287 };
288
289 template <typename T>
290 struct is_same<T, T>
291 {
292 static const bool value = true;
293 };
294
295 template<typename T>
296 struct add_const
297 { typedef const T type; };
298
299 template<typename T>
300 struct remove_const
301 { typedef T type; };
302
303 template<typename T>
304 struct remove_const<const T>
305 { typedef T type; };
306
307 template<typename T>
308 struct remove_cv
309 { typedef T type; };
310
311 template<typename T>
312 struct remove_cv<const T>
313 { typedef T type; };
314
315 template<typename T>
316 struct remove_cv<const volatile T>
317 { typedef T type; };
318
319 template<typename T>
320 struct remove_cv<volatile T>
321 { typedef T type; };
322
323 template<class T>
324 struct remove_reference
325 {
326 typedef T type;
327 };
328
329 template<class T>
330 struct remove_reference<T&>
331 {
332 typedef T type;
333 }; 262 };
334 263
335 template<class Class> 264 template<class Class>
336 class is_empty_class 265 class is_empty_class
337 { 266 {
365 struct ls_zeros<1> 294 struct ls_zeros<1>
366 { 295 {
367 static const std::size_t value = 0; 296 static const std::size_t value = 0;
368 }; 297 };
369 298
299 template <typename T> struct unvoid_ref { typedef T &type; };
300 template <> struct unvoid_ref<void> { struct type_impl { }; typedef type_impl & type; };
301 template <> struct unvoid_ref<const void> { struct type_impl { }; typedef type_impl & type; };
302
303 // Infrastructure for providing a default type for T::TNAME if absent.
304 #define BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(TNAME) \
305 template <typename T, typename DefaultType> \
306 struct boost_intrusive_default_type_ ## TNAME \
307 { \
308 template <typename X> \
309 static char test(int, typename X::TNAME*); \
310 \
311 template <typename X> \
312 static int test(...); \
313 \
314 struct DefaultWrap { typedef DefaultType TNAME; }; \
315 \
316 static const bool value = (1 == sizeof(test<T>(0, 0))); \
317 \
318 typedef typename \
319 ::boost::intrusive::detail::if_c \
320 <value, T, DefaultWrap>::type::TNAME type; \
321 }; \
322 //
323
324 #define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
325 typename INSTANTIATION_NS_PREFIX \
326 boost_intrusive_default_type_ ## TNAME< T, TIMPL >::type \
327 //
328
329 #define BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(TNAME)\
330 template <typename T, typename DefaultType> \
331 struct boost_intrusive_eval_default_type_ ## TNAME \
332 { \
333 template <typename X> \
334 static char test(int, typename X::TNAME*); \
335 \
336 template <typename X> \
337 static int test(...); \
338 \
339 struct DefaultWrap \
340 { typedef typename DefaultType::type TNAME; }; \
341 \
342 static const bool value = (1 == sizeof(test<T>(0, 0))); \
343 \
344 typedef typename \
345 ::boost::intrusive::detail::eval_if_c \
346 < value \
347 , ::boost::intrusive::detail::identity<T> \
348 , ::boost::intrusive::detail::identity<DefaultWrap> \
349 >::type::TNAME type; \
350 }; \
351 //
352
353 #define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
354 typename INSTANTIATION_NS_PREFIX \
355 boost_intrusive_eval_default_type_ ## TNAME< T, TIMPL >::type \
356 //
357
358 #define BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(TRAITS_PREFIX, TYPEDEF_TO_FIND) \
359 template <class T>\
360 struct TRAITS_PREFIX##_bool\
361 {\
362 template<bool Add>\
363 struct two_or_three {one _[2 + Add];};\
364 template <class U> static one test(...);\
365 template <class U> static two_or_three<U::TYPEDEF_TO_FIND> test (int);\
366 static const std::size_t value = sizeof(test<T>(0));\
367 };\
368 \
369 template <class T>\
370 struct TRAITS_PREFIX##_bool_is_true\
371 {\
372 static const bool value = TRAITS_PREFIX##_bool<T>::value > sizeof(one)*2;\
373 };\
374 //
375
376 #define BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(TRAITS_NAME, FUNC_NAME) \
377 template <typename U, typename Signature> \
378 class TRAITS_NAME \
379 { \
380 private: \
381 template<Signature> struct helper;\
382 template<typename T> \
383 static ::boost::intrusive::detail::yes_type check(helper<&T::FUNC_NAME>*); \
384 template<typename T> static ::boost::intrusive::detail::no_type check(...); \
385 public: \
386 static const bool value = sizeof(check<U>(0)) == sizeof(::boost::intrusive::detail::yes_type); \
387 }; \
388 //
389
390 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(TRAITS_NAME, FUNC_NAME) \
391 template <typename Type> \
392 struct TRAITS_NAME \
393 { \
394 struct BaseMixin \
395 { \
396 void FUNC_NAME(); \
397 }; \
398 struct Base : public Type, public BaseMixin { Base(); }; \
399 template <typename T, T t> class Helper{}; \
400 template <typename U> \
401 static ::boost::intrusive::detail::no_type check(U*, Helper<void (BaseMixin::*)(), &U::FUNC_NAME>* = 0); \
402 static ::boost::intrusive::detail::yes_type check(...); \
403 static const bool value = sizeof(::boost::intrusive::detail::yes_type) == sizeof(check((Base*)(0))); \
404 };\
405 //
406
407 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(TRAITS_NAME, FUNC_NAME) \
408 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(TRAITS_NAME##_ignore_signature, FUNC_NAME) \
409 \
410 template <typename Type, class> \
411 struct TRAITS_NAME \
412 : public TRAITS_NAME##_ignore_signature<Type> \
413 {};\
414 //
415
416
417 template <typename T>
418 inline T* addressof(T& obj)
419 {
420 return static_cast<T*>
421 (static_cast<void*>
422 (const_cast<char*>
423 (&reinterpret_cast<const char&>(obj))
424 )
425 );
426 }
427
370 } //namespace detail 428 } //namespace detail
371 } //namespace intrusive 429 } //namespace intrusive
372 } //namespace boost 430 } //namespace boost
373 431
374 #include <boost/intrusive/detail/config_end.hpp> 432 #include <boost/intrusive/detail/config_end.hpp>