1/////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2006-2014
4// (C) Copyright Microsoft Corporation 2014
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9//
10// See http://www.boost.org/libs/intrusive for documentation.
11//
12/////////////////////////////////////////////////////////////////////////////
13
14#ifndef BOOST_INTRUSIVE_DETAIL_MPL_HPP
15#define BOOST_INTRUSIVE_DETAIL_MPL_HPP
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
25#include <boost/intrusive/detail/config_begin.hpp>
26#include <boost/move/detail/type_traits.hpp>
27#include <cstddef>
28
29namespace boost {
30namespace intrusive {
31namespace detail {
32
33using boost::move_detail::is_same;
34using boost::move_detail::add_const;
35using boost::move_detail::remove_const;
36using boost::move_detail::remove_cv;
37using boost::move_detail::remove_reference;
38using boost::move_detail::add_reference;
39using boost::move_detail::remove_pointer;
40using boost::move_detail::add_pointer;
41using boost::move_detail::true_type;
42using boost::move_detail::false_type;
43using boost::move_detail::enable_if_c;
44using boost::move_detail::enable_if;
45using boost::move_detail::disable_if_c;
46using boost::move_detail::disable_if;
47using boost::move_detail::is_convertible;
48using boost::move_detail::if_c;
49using boost::move_detail::if_;
50using boost::move_detail::is_const;
51using boost::move_detail::identity;
52using boost::move_detail::alignment_of;
53using boost::move_detail::is_empty;
54using boost::move_detail::addressof;
55using boost::move_detail::integral_constant;
56using boost::move_detail::enable_if_convertible;
57using boost::move_detail::disable_if_convertible;
58using boost::move_detail::bool_;
59using boost::move_detail::true_;
60using boost::move_detail::false_;
61using boost::move_detail::yes_type;
62using boost::move_detail::no_type;
63using boost::move_detail::apply;
64using boost::move_detail::eval_if_c;
65using boost::move_detail::eval_if;
66using boost::move_detail::unvoid_ref;
67using boost::move_detail::add_const_if_c;
68
69template<std::size_t S>
70struct ls_zeros
71{
72 static const std::size_t value = (S & std::size_t(1)) ? 0 : (1 + ls_zeros<(S>>1u)>::value);
73};
74
75template<>
76struct ls_zeros<0>
77{
78 static const std::size_t value = 0;
79};
80
81template<>
82struct ls_zeros<1>
83{
84 static const std::size_t value = 0;
85};
86
87// Infrastructure for providing a default type for T::TNAME if absent.
88#define BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(TNAME) \
89 template <typename T, typename DefaultType> \
90 struct boost_intrusive_default_type_ ## TNAME \
91 { \
92 template <typename X> \
93 static char test(int, typename X::TNAME*); \
94 \
95 template <typename X> \
96 static int test(...); \
97 \
98 struct DefaultWrap { typedef DefaultType TNAME; }; \
99 \
100 static const bool value = (1 == sizeof(test<T>(0, 0))); \
101 \
102 typedef typename \
103 ::boost::intrusive::detail::if_c \
104 <value, T, DefaultWrap>::type::TNAME type; \
105 }; \
106 //
107
108#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
109 typename INSTANTIATION_NS_PREFIX \
110 boost_intrusive_default_type_ ## TNAME< T, TIMPL >::type \
111//
112
113#define BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(TNAME)\
114 template <typename T, typename DefaultType> \
115 struct boost_intrusive_eval_default_type_ ## TNAME \
116 { \
117 template <typename X> \
118 static char test(int, typename X::TNAME*); \
119 \
120 template <typename X> \
121 static int test(...); \
122 \
123 struct DefaultWrap \
124 { typedef typename DefaultType::type TNAME; }; \
125 \
126 static const bool value = (1 == sizeof(test<T>(0, 0))); \
127 \
128 typedef typename \
129 ::boost::intrusive::detail::eval_if_c \
130 < value \
131 , ::boost::intrusive::detail::identity<T> \
132 , ::boost::intrusive::detail::identity<DefaultWrap> \
133 >::type::TNAME type; \
134 }; \
135//
136
137#define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
138 typename INSTANTIATION_NS_PREFIX \
139 boost_intrusive_eval_default_type_ ## TNAME< T, TIMPL >::type \
140//
141
142#define BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(TRAITS_PREFIX, TYPEDEF_TO_FIND) \
143template <class T>\
144struct TRAITS_PREFIX##_bool\
145{\
146 template<bool Add>\
147 struct two_or_three {yes_type _[2 + Add];};\
148 template <class U> static yes_type test(...);\
149 template <class U> static two_or_three<U::TYPEDEF_TO_FIND> test (int);\
150 static const std::size_t value = sizeof(test<T>(0));\
151};\
152\
153template <class T>\
154struct TRAITS_PREFIX##_bool_is_true\
155{\
156 static const bool value = TRAITS_PREFIX##_bool<T>::value > sizeof(yes_type)*2;\
157};\
158//
159
160#define BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(TRAITS_NAME, FUNC_NAME) \
161 template <typename U, typename Signature> \
162 class TRAITS_NAME \
163 { \
164 private: \
165 template<Signature> struct helper;\
166 template<typename T> \
167 static ::boost::intrusive::detail::yes_type test(helper<&T::FUNC_NAME>*); \
168 template<typename T> static ::boost::intrusive::detail::no_type test(...); \
169 public: \
170 static const bool value = sizeof(test<U>(0)) == sizeof(::boost::intrusive::detail::yes_type); \
171 }; \
172//
173
174#define BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(TRAITS_NAME, FUNC_NAME) \
175template <typename Type> \
176struct TRAITS_NAME \
177{ \
178 struct BaseMixin \
179 { \
180 void FUNC_NAME(); \
181 }; \
182 struct Base : public Type, public BaseMixin { Base(); }; \
183 template <typename T, T t> class Helper{}; \
184 template <typename U> \
185 static ::boost::intrusive::detail::no_type test(U*, Helper<void (BaseMixin::*)(), &U::FUNC_NAME>* = 0); \
186 static ::boost::intrusive::detail::yes_type test(...); \
187 static const bool value = sizeof(::boost::intrusive::detail::yes_type) == sizeof(test((Base*)(0))); \
188};\
189//
190
191#define BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(TRAITS_NAME, FUNC_NAME) \
192BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(TRAITS_NAME##_ignore_signature, FUNC_NAME) \
193\
194template <typename Type, class> \
195struct TRAITS_NAME \
196 : public TRAITS_NAME##_ignore_signature<Type> \
197{};\
198//
199
200} //namespace detail
201} //namespace intrusive
202} //namespace boost
203
204#include <boost/intrusive/detail/config_end.hpp>
205
206#endif //BOOST_INTRUSIVE_DETAIL_MPL_HPP
207