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::enable_if_c;
44 using boost::move_detail::enable_if;
45 using boost::move_detail::disable_if_c;
46 using boost::move_detail::disable_if;
47 using boost::move_detail::is_convertible;
48 using boost::move_detail::if_c;
49 using boost::move_detail::if_;
50 using boost::move_detail::is_const;
51 using boost::move_detail::identity;
52 using boost::move_detail::alignment_of;
53 using boost::move_detail::is_empty;
54 using boost::move_detail::addressof;
55 using boost::move_detail::integral_constant;
56 using boost::move_detail::enable_if_convertible;
57 using boost::move_detail::disable_if_convertible;
58 using boost::move_detail::bool_;
59 using boost::move_detail::true_;
60 using boost::move_detail::false_;
61 using boost::move_detail::yes_type;
62 using boost::move_detail::no_type;
63 using boost::move_detail::apply;
64 using boost::move_detail::eval_if_c;
65 using boost::move_detail::eval_if;
66 using boost::move_detail::unvoid_ref;
67 using boost::move_detail::add_const_if_c;
69 template<std::size_t S>
72 static const std::size_t value = (S & std::size_t(1)) ? 0 : (1 + ls_zeros<(S>>1u)>::value);
78 static const std::size_t value = 0;
84 static const std::size_t value = 0;
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> \
90 struct boost_intrusive_has_type_ ## TNAME \
92 template <typename X> \
93 static char test(int, typename X::TNAME*); \
95 template <typename X> \
96 static int test(...); \
98 static const bool value = (1 == sizeof(test<T>(0, 0))); \
101 template <typename T, typename DefaultType> \
102 struct boost_intrusive_default_type_ ## TNAME \
104 struct DefaultWrap { typedef DefaultType TNAME; }; \
107 ::boost::intrusive::detail::if_c \
108 < boost_intrusive_has_type_ ## TNAME<T>::value \
109 , T, DefaultWrap>::type::TNAME type; \
113 #define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
114 typename INSTANTIATION_NS_PREFIX \
115 boost_intrusive_default_type_ ## TNAME< T, TIMPL >::type \
118 #define BOOST_INTRUSIVE_HAS_TYPE(INSTANTIATION_NS_PREFIX, T, TNAME) \
119 INSTANTIATION_NS_PREFIX \
120 boost_intrusive_has_type_ ## TNAME< T >::value \
123 #define BOOST_INTRUSIVE_INSTANTIATE_EVAL_DEFAULT_TYPE_TMPLT(TNAME)\
124 template <typename T, typename DefaultType> \
125 struct boost_intrusive_eval_default_type_ ## TNAME \
127 template <typename X> \
128 static char test(int, typename X::TNAME*); \
130 template <typename X> \
131 static int test(...); \
134 { typedef typename DefaultType::type TNAME; }; \
136 static const bool value = (1 == sizeof(test<T>(0, 0))); \
139 ::boost::intrusive::detail::eval_if_c \
141 , ::boost::intrusive::detail::identity<T> \
142 , ::boost::intrusive::detail::identity<DefaultWrap> \
143 >::type::TNAME type; \
147 #define BOOST_INTRUSIVE_OBTAIN_TYPE_WITH_EVAL_DEFAULT(INSTANTIATION_NS_PREFIX, T, TNAME, TIMPL) \
148 typename INSTANTIATION_NS_PREFIX \
149 boost_intrusive_eval_default_type_ ## TNAME< T, TIMPL >::type \
152 #define BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(TRAITS_PREFIX, TYPEDEF_TO_FIND) \
154 struct TRAITS_PREFIX##_bool\
157 struct two_or_three {yes_type _[2 + Add];};\
158 template <class U> static yes_type test(...);\
159 template <class U> static two_or_three<U::TYPEDEF_TO_FIND> test (int);\
160 static const std::size_t value = sizeof(test<T>(0));\
164 struct TRAITS_PREFIX##_bool_is_true\
166 static const bool value = TRAITS_PREFIX##_bool<T>::value > sizeof(yes_type)*2;\
170 #define BOOST_INTRUSIVE_HAS_STATIC_MEMBER_FUNC_SIGNATURE(TRAITS_NAME, FUNC_NAME) \
171 template <typename U, typename Signature> \
175 template<Signature> struct helper;\
176 template<typename T> \
177 static ::boost::intrusive::detail::yes_type test(helper<&T::FUNC_NAME>*); \
178 template<typename T> static ::boost::intrusive::detail::no_type test(...); \
180 static const bool value = sizeof(test<U>(0)) == sizeof(::boost::intrusive::detail::yes_type); \
184 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(TRAITS_NAME, FUNC_NAME) \
185 template <typename Type> \
192 struct Base : public Type, public BaseMixin { Base(); }; \
193 template <typename T, T t> class Helper{}; \
194 template <typename U> \
195 static ::boost::intrusive::detail::no_type test(U*, Helper<void (BaseMixin::*)(), &U::FUNC_NAME>* = 0); \
196 static ::boost::intrusive::detail::yes_type test(...); \
197 static const bool value = sizeof(::boost::intrusive::detail::yes_type) == sizeof(test((Base*)(0))); \
201 #define BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED_IGNORE_SIGNATURE(TRAITS_NAME, FUNC_NAME) \
202 BOOST_INTRUSIVE_HAS_MEMBER_FUNC_CALLED(TRAITS_NAME##_ignore_signature, FUNC_NAME) \
204 template <typename Type, class> \
206 : public TRAITS_NAME##_ignore_signature<Type> \
211 } //namespace intrusive
214 #include <boost/intrusive/detail/config_end.hpp>
216 #endif //BOOST_INTRUSIVE_DETAIL_MPL_HPP