Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // |
| 3 | // (C) Copyright Ion Gaztanaga 2006-2012 |
| 4 | // |
| 5 | // Distributed under the Boost Software License, Version 1.0. |
| 6 | // (See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt) |
| 8 | // |
| 9 | // See http://www.boost.org/libs/intrusive for documentation. |
| 10 | // |
| 11 | ///////////////////////////////////////////////////////////////////////////// |
| 12 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 13 | #ifndef NDNBOOST_INTRUSIVE_DETAIL_MPL_HPP |
| 14 | #define NDNBOOST_INTRUSIVE_DETAIL_MPL_HPP |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 15 | |
| 16 | #include <ndnboost/intrusive/detail/config_begin.hpp> |
| 17 | #include <cstddef> |
| 18 | |
| 19 | namespace ndnboost { |
| 20 | namespace intrusive { |
| 21 | namespace detail { |
| 22 | |
| 23 | typedef char one; |
| 24 | struct two {one _[2];}; |
| 25 | |
| 26 | template< bool C_ > |
| 27 | struct bool_ |
| 28 | { |
| 29 | static const bool value = C_; |
| 30 | }; |
| 31 | |
| 32 | typedef bool_<true> true_; |
| 33 | typedef bool_<false> false_; |
| 34 | |
| 35 | typedef true_ true_type; |
| 36 | typedef false_ false_type; |
| 37 | |
| 38 | typedef char yes_type; |
| 39 | struct no_type |
| 40 | { |
| 41 | char padding[8]; |
| 42 | }; |
| 43 | |
| 44 | template <bool B, class T = void> |
| 45 | struct enable_if_c { |
| 46 | typedef T type; |
| 47 | }; |
| 48 | |
| 49 | template <class T> |
| 50 | struct enable_if_c<false, T> {}; |
| 51 | |
| 52 | template <class Cond, class T = void> |
| 53 | struct enable_if : public enable_if_c<Cond::value, T>{}; |
| 54 | |
| 55 | template<class F, class Param> |
| 56 | struct apply |
| 57 | { |
| 58 | typedef typename F::template apply<Param>::type type; |
| 59 | }; |
| 60 | |
| 61 | template <class T, class U> |
| 62 | class is_convertible |
| 63 | { |
| 64 | typedef char true_t; |
| 65 | class false_t { char dummy[2]; }; |
| 66 | static true_t dispatch(U); |
| 67 | static false_t dispatch(...); |
| 68 | static const T &trigger(); |
| 69 | public: |
| 70 | static const bool value = sizeof(dispatch(trigger())) == sizeof(true_t); |
| 71 | }; |
| 72 | |
| 73 | template< |
| 74 | bool C |
| 75 | , typename T1 |
| 76 | , typename T2 |
| 77 | > |
| 78 | struct if_c |
| 79 | { |
| 80 | typedef T1 type; |
| 81 | }; |
| 82 | |
| 83 | template< |
| 84 | typename T1 |
| 85 | , typename T2 |
| 86 | > |
| 87 | struct if_c<false,T1,T2> |
| 88 | { |
| 89 | typedef T2 type; |
| 90 | }; |
| 91 | |
| 92 | template< |
| 93 | typename C |
| 94 | , typename T1 |
| 95 | , typename T2 |
| 96 | > |
| 97 | struct if_ |
| 98 | { |
| 99 | typedef typename if_c<0 != C::value, T1, T2>::type type; |
| 100 | }; |
| 101 | |
| 102 | template< |
| 103 | bool C |
| 104 | , typename F1 |
| 105 | , typename F2 |
| 106 | > |
| 107 | struct eval_if_c |
| 108 | : if_c<C,F1,F2>::type |
| 109 | {}; |
| 110 | |
| 111 | template< |
| 112 | typename C |
| 113 | , typename T1 |
| 114 | , typename T2 |
| 115 | > |
| 116 | struct eval_if |
| 117 | : if_<C,T1,T2>::type |
| 118 | {}; |
| 119 | |
| 120 | // identity is an extension: it is not part of the standard. |
| 121 | template <class T> |
| 122 | struct identity |
| 123 | { |
| 124 | typedef T type; |
| 125 | }; |
| 126 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 127 | #if defined(NDNBOOST_MSVC) || defined(__BORLANDC_) |
| 128 | #define NDNBOOST_INTRUSIVE_TT_DECL __cdecl |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 129 | #else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 130 | #define NDNBOOST_INTRUSIVE_TT_DECL |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 131 | #endif |
| 132 | |
| 133 | #if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64) && !defined(UNDER_CE) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 134 | #define NDNBOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 135 | #endif |
| 136 | |
| 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 |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 143 | #ifndef NDNBOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 153 | #else // NDNBOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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 |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 179 | #ifndef NDNBOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 189 | #else // NDNBOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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 |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 215 | #ifndef NDNBOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 225 | #else // NDNBOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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 | |
| 256 | //ndnboost::alignment_of yields to 10K lines of preprocessed code, so we |
| 257 | //need an alternative |
| 258 | template <typename T> struct alignment_of; |
| 259 | |
| 260 | template <typename T> |
| 261 | struct alignment_of_hack |
| 262 | { |
| 263 | char c; |
| 264 | T t; |
| 265 | alignment_of_hack(); |
| 266 | }; |
| 267 | |
| 268 | template <unsigned A, unsigned S> |
| 269 | struct alignment_logic |
| 270 | { |
| 271 | static const std::size_t value = A < S ? A : S; |
| 272 | }; |
| 273 | |
| 274 | template< typename T > |
| 275 | struct alignment_of |
| 276 | { |
| 277 | static const std::size_t value = alignment_logic |
| 278 | < sizeof(alignment_of_hack<T>) - sizeof(T) |
| 279 | , sizeof(T) |
| 280 | >::value; |
| 281 | }; |
| 282 | |
| 283 | template <typename T, typename U> |
| 284 | struct is_same |
| 285 | { |
| 286 | typedef char yes_type; |
| 287 | struct no_type |
| 288 | { |
| 289 | char padding[8]; |
| 290 | }; |
| 291 | |
| 292 | template <typename V> |
| 293 | static yes_type is_same_tester(V*, V*); |
| 294 | static no_type is_same_tester(...); |
| 295 | |
| 296 | static T *t; |
| 297 | static U *u; |
| 298 | |
| 299 | static const bool value = sizeof(yes_type) == sizeof(is_same_tester(t,u)); |
| 300 | }; |
| 301 | |
| 302 | template<typename T> |
| 303 | struct add_const |
| 304 | { typedef const T type; }; |
| 305 | |
| 306 | template<typename T> |
| 307 | struct remove_const |
| 308 | { typedef T type; }; |
| 309 | |
| 310 | template<typename T> |
| 311 | struct remove_const<const T> |
| 312 | { typedef T type; }; |
| 313 | |
| 314 | template<typename T> |
| 315 | struct remove_cv |
| 316 | { typedef T type; }; |
| 317 | |
| 318 | template<typename T> |
| 319 | struct remove_cv<const T> |
| 320 | { typedef T type; }; |
| 321 | |
| 322 | template<typename T> |
| 323 | struct remove_cv<const volatile T> |
| 324 | { typedef T type; }; |
| 325 | |
| 326 | template<typename T> |
| 327 | struct remove_cv<volatile T> |
| 328 | { typedef T type; }; |
| 329 | |
| 330 | template<class T> |
| 331 | struct remove_reference |
| 332 | { |
| 333 | typedef T type; |
| 334 | }; |
| 335 | |
| 336 | template<class T> |
| 337 | struct remove_reference<T&> |
| 338 | { |
| 339 | typedef T type; |
| 340 | }; |
| 341 | |
| 342 | template<class Class> |
| 343 | class is_empty_class |
| 344 | { |
| 345 | template <typename T> |
| 346 | struct empty_helper_t1 : public T |
| 347 | { |
| 348 | empty_helper_t1(); |
| 349 | int i[256]; |
| 350 | }; |
| 351 | |
| 352 | struct empty_helper_t2 |
| 353 | { int i[256]; }; |
| 354 | |
| 355 | public: |
| 356 | static const bool value = sizeof(empty_helper_t1<Class>) == sizeof(empty_helper_t2); |
| 357 | }; |
| 358 | |
| 359 | template<std::size_t S> |
| 360 | struct ls_zeros |
| 361 | { |
| 362 | static const std::size_t value = (S & std::size_t(1)) ? 0 : (1 + ls_zeros<(S>>1u)>::value); |
| 363 | }; |
| 364 | |
| 365 | template<> |
| 366 | struct ls_zeros<0> |
| 367 | { |
| 368 | static const std::size_t value = 0; |
| 369 | }; |
| 370 | |
| 371 | template<> |
| 372 | struct ls_zeros<1> |
| 373 | { |
| 374 | static const std::size_t value = 0; |
| 375 | }; |
| 376 | |
| 377 | } //namespace detail |
| 378 | } //namespace intrusive |
| 379 | } //namespace ndnboost |
| 380 | |
| 381 | #include <ndnboost/intrusive/detail/config_end.hpp> |
| 382 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 383 | #endif //NDNBOOST_INTRUSIVE_DETAIL_MPL_HPP |