mpl.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2016.
  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<
  56. bool C
  57. , typename T1
  58. , typename T2
  59. >
  60. struct if_c
  61. {
  62. typedef T1 type;
  63. };
  64. template<
  65. typename T1
  66. , typename T2
  67. >
  68. struct if_c<false,T1,T2>
  69. {
  70. typedef T2 type;
  71. };
  72. template<
  73. typename T1
  74. , typename T2
  75. , typename T3
  76. >
  77. struct if_
  78. {
  79. typedef typename if_c<0 != T1::value, T2, T3>::type type;
  80. };
  81. template<std::size_t S>
  82. struct ls_zeros
  83. {
  84. static const std::size_t value = (S & std::size_t(1)) ? 0 : (1u + ls_zeros<(S >> 1u)>::value);
  85. };
  86. template<>
  87. struct ls_zeros<0>
  88. {
  89. static const std::size_t value = 0;
  90. };
  91. template<>
  92. struct ls_zeros<1>
  93. {
  94. static const std::size_t value = 0;
  95. };
  96. } //namespace ipcdetail {
  97. } //namespace interprocess {
  98. } //namespace boost {
  99. #endif //#ifndef BOOST_INTERPROCESS_DETAIL_MPL_HPP