mpl.hpp 3.1 KB

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