1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2006-2014
4 // (C) Copyright Microsoft Corporation 2014
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)
10 // See http://www.boost.org/libs/intrusive for documentation.
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef BOOST_INTRUSIVE_DETAIL_MPL_HPP
15 #define BOOST_INTRUSIVE_DETAIL_MPL_HPP
17 #ifndef BOOST_CONFIG_HPP
18 # include <boost/config.hpp>
21 #if defined(BOOST_HAS_PRAGMA_ONCE)
25 #include <boost/intrusive/detail/config_begin.hpp>
26 #include <boost/move/detail/type_traits.hpp>
33 using boost::move_detail::is_same;
34 using boost::move_detail::add_const;
35 using boost::move_detail::remove_const;
36 using boost::move_detail::remove_cv;
37 using boost::move_detail::remove_reference;
38 using boost::move_detail::add_reference;
39 using boost::move_detail::remove_pointer;
40 using boost::move_detail::add_pointer;
41 using boost::move_detail::true_type;
42 using boost::move_detail::false_type;
43 using boost::move_detail::voider;
44 using boost::move_detail::enable_if_c;
45 using boost::move_detail::enable_if;
46 using boost::move_detail::disable_if_c;
47 using boost::move_detail::disable_if;
48 using boost::move_detail::is_convertible;
49 using boost::move_detail::if_c;
50 using boost::move_detail::if_;
51 using boost::move_detail::is_const;
52 using boost::move_detail::identity;
53 using boost::move_detail::alignment_of;
54 using boost::move_detail::is_empty;
55 using boost::move_detail::addressof;
56 using boost::move_detail::integral_constant;
57 using boost::move_detail::enable_if_convertible;
58 using boost::move_detail::disable_if_convertible;
59 using boost::move_detail::bool_;
60 using boost::move_detail::true_;
61 using boost::move_detail::false_;
62 using boost::move_detail::yes_type;
63 using boost::move_detail::no_type;
64 using boost::move_detail::apply;
65 using boost::move_detail::eval_if_c;
66 using boost::move_detail::eval_if;
67 using boost::move_detail::unvoid_ref;
68 using boost::move_detail::add_const_if_c;
70 template<std::size_t S>
73 static const std::size_t value = (S & std::size_t(1)) ? 0 : (1 + ls_zeros<(S>>1u)>::value);
79 static const std::size_t value = 0;
85 static const std::size_t value = 0;
88 // Infrastructure for providing a default type for T::TNAME if absent.
89 #define BOOST_INTRUSIVE_INSTANTIATE_DEFAULT_TYPE_TMPLT(TNAME) \
90 template <typename T> \
91 struct boost_intrusive_has_type_ ## TNAME \
93 template <typename X> \
94 static char test(int, typename X::TNAME*); \
96 template <typename X> \
97 static int test(...); \
99 static const bool value = (1 == sizeof(test<T>(0, 0))); \
102 template <typename T, typename DefaultType> \
103 struct boost_intrusive_default_type_ ## TNAME \
105 struct DefaultWrap { typedef DefaultType TNAME; }; \
108 ::boost::intrusive::detail::if_c \
109 < boost_intrusive_has_type_ ## TNAME<T>::value \
110 , T, DefaultWrap>::type::TNAME type; \
114 #define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
115 typename INSTANTIATION_NS_PREFIX \
116 boost_intrusive_default_type_ ## TNAME< T, TIMPL >::type \
119 #define BOOST_INTRUSIVE_HAS_TYPE(INSTANTIATION_NS_PREFIX, T, TNAME) \
120 INSTANTIATION_NS_PREFIX \
121 boost_intrusive_has_type_ ## TNAME< T >::value \
124 #define BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(TNAME)\
125 template <typename T, typename DefaultType> \
126 struct boost_intrusive_eval_default_type_ ## TNAME \
128 template <typename X> \
129 static char test(int, typename X::TNAME*); \
131 template <typename X> \
132 static int test(...); \
135 { typedef typename DefaultType::type TNAME; }; \
137 static const bool value = (1 == sizeof(test<T>(0, 0))); \
140 ::boost::intrusive::detail::eval_if_c \
142 , ::boost::intrusive::detail::identity<T> \
143 , ::boost::intrusive::detail::identity<DefaultWrap> \
144 >::type::TNAME type; \
148 #define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
149 typename INSTANTIATION_NS_PREFIX \
150 boost_intrusive_eval_default_type_ ## TNAME< T, TIMPL >::type \
153 #define BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(TRAITS_PREFIX, TYPEDEF_TO_FIND) \
155 struct TRAITS_PREFIX##_bool\
158 struct two_or_three {yes_type _[2 + Add];};\
159 template <class U> static yes_type test(...);\
160 template <class U> static two_or_three<U::TYPEDEF_TO_FIND> test (int);\
161 static const std::size_t value = sizeof(test<T>(0));\
165 struct TRAITS_PREFIX##_bool_is_true\
167 static const bool value = TRAITS_PREFIX##_bool<T>::value > sizeof(yes_type)*2;\
171 #define BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(TRAITS_NAME, FUNC_NAME) \
172 template <typename U, typename Signature> \
176 template<Signature> struct helper;\
177 template<typename T> \
178 static ::boost::intrusive::detail::yes_type test(helper<&T::FUNC_NAME>*); \
179 template<typename T> static ::boost::intrusive::detail::no_type test(...); \
181 static const bool value = sizeof(test<U>(0)) == sizeof(::boost::intrusive::detail::yes_type); \
185 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(TRAITS_NAME, FUNC_NAME) \
186 template <typename Type> \
193 struct Base : public Type, public BaseMixin { Base(); }; \
194 template <typename T, T t> class Helper{}; \
195 template <typename U> \
196 static ::boost::intrusive::detail::no_type test(U*, Helper<void (BaseMixin::*)(), &U::FUNC_NAME>* = 0); \
197 static ::boost::intrusive::detail::yes_type test(...); \
198 static const bool value = sizeof(::boost::intrusive::detail::yes_type) == sizeof(test((Base*)(0))); \
202 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(TRAITS_NAME, FUNC_NAME) \
203 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(TRAITS_NAME##_ignore_signature, FUNC_NAME) \
205 template <typename Type, class> \
207 : public TRAITS_NAME##_ignore_signature<Type> \
212 } //namespace intrusive
215 #include <boost/intrusive/detail/config_end.hpp>
217 #endif //BOOST_INTRUSIVE_DETAIL_MPL_HPP