mpl.hpp 3.0 KB

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