mpl.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-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/container for documentation.
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_CONTAINER_CONTAINER_DETAIL_MPL_HPP
  13. #define BOOST_CONTAINER_CONTAINER_DETAIL_MPL_HPP
  14. #if defined(_MSC_VER)
  15. # pragma once
  16. #endif
  17. #include <cstddef>
  18. namespace boost {
  19. namespace container {
  20. namespace container_detail {
  21. template <class T, T val>
  22. struct integral_constant
  23. {
  24. static const T value = val;
  25. typedef integral_constant<T,val> type;
  26. };
  27. template< bool C_ >
  28. struct bool_ : integral_constant<bool, C_>
  29. {
  30. static const bool value = C_;
  31. operator bool() const { return bool_::value; }
  32. };
  33. typedef bool_<true> true_;
  34. typedef bool_<false> false_;
  35. typedef true_ true_type;
  36. typedef false_ false_type;
  37. typedef char yes_type;
  38. struct no_type
  39. {
  40. char padding[8];
  41. };
  42. template <bool B, class T = void>
  43. struct enable_if_c {
  44. typedef T type;
  45. };
  46. template <class T>
  47. struct enable_if_c<false, T> {};
  48. template <class Cond, class T = void>
  49. struct enable_if : public enable_if_c<Cond::value, T> {};
  50. template <class Cond, class T = void>
  51. struct disable_if : public enable_if_c<!Cond::value, T> {};
  52. template <bool B, class T = void>
  53. struct disable_if_c : public enable_if_c<!B, T> {};
  54. template <class T, class U>
  55. class is_convertible
  56. {
  57. typedef char true_t;
  58. class false_t { char dummy[2]; };
  59. static true_t dispatch(U);
  60. static false_t dispatch(...);
  61. static T trigger();
  62. public:
  63. enum { value = sizeof(dispatch(trigger())) == sizeof(true_t) };
  64. };
  65. template<
  66. bool C
  67. , typename T1
  68. , typename T2
  69. >
  70. struct if_c
  71. {
  72. typedef T1 type;
  73. };
  74. template<
  75. typename T1
  76. , typename T2
  77. >
  78. struct if_c<false,T1,T2>
  79. {
  80. typedef T2 type;
  81. };
  82. template<
  83. typename T1
  84. , typename T2
  85. , typename T3
  86. >
  87. struct if_
  88. {
  89. typedef typename if_c<0 != T1::value, T2, T3>::type type;
  90. };
  91. template <class Pair>
  92. struct select1st
  93. // : public std::unary_function<Pair, typename Pair::first_type>
  94. {
  95. template<class OtherPair>
  96. const typename Pair::first_type& operator()(const OtherPair& x) const
  97. { return x.first; }
  98. const typename Pair::first_type& operator()(const typename Pair::first_type& x) const
  99. { return x; }
  100. };
  101. // identity is an extension: it is not part of the standard.
  102. template <class T>
  103. struct identity
  104. // : public std::unary_function<T,T>
  105. {
  106. typedef T type;
  107. const T& operator()(const T& x) const
  108. { return x; }
  109. };
  110. template<std::size_t S>
  111. struct ls_zeros
  112. {
  113. static const std::size_t value = (S & std::size_t(1)) ? 0 : (1u + ls_zeros<(S >> 1u)>::value);
  114. };
  115. template<>
  116. struct ls_zeros<0>
  117. {
  118. static const std::size_t value = 0;
  119. };
  120. template<>
  121. struct ls_zeros<1>
  122. {
  123. static const std::size_t value = 0;
  124. };
  125. template <typename T> struct unvoid { typedef T type; };
  126. template <> struct unvoid<void> { struct type { }; };
  127. template <> struct unvoid<const void> { struct type { }; };
  128. } //namespace container_detail {
  129. } //namespace container {
  130. } //namespace boost {
  131. #endif //#ifndef BOOST_CONTAINER_CONTAINER_DETAIL_MPL_HPP