type_traits.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //////////////////////////////////////////////////////////////////////////////
  2. // (C) Copyright John Maddock 2000.
  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_TYPE_TRAITS_HPP
  13. #define BOOST_INTERPROCESS_DETAIL_TYPE_TRAITS_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 <boost/interprocess/detail/config_begin.hpp>
  22. namespace boost {
  23. namespace interprocess {
  24. namespace ipcdetail {
  25. struct nat{};
  26. template<class T>
  27. struct remove_reference
  28. {
  29. typedef T type;
  30. };
  31. template<class T>
  32. struct remove_reference<T&>
  33. {
  34. typedef T type;
  35. };
  36. template<class T>
  37. struct is_reference
  38. {
  39. static const bool value = false;
  40. };
  41. template<class T>
  42. struct is_reference<T&>
  43. {
  44. static const bool value = true;
  45. };
  46. template<class T>
  47. struct is_pointer
  48. {
  49. static const bool value = false;
  50. };
  51. template<class T>
  52. struct is_pointer<T*>
  53. {
  54. static const bool value = true;
  55. };
  56. template <typename T>
  57. struct add_reference
  58. {
  59. typedef T& type;
  60. };
  61. template<class T>
  62. struct add_reference<T&>
  63. {
  64. typedef T& type;
  65. };
  66. template<>
  67. struct add_reference<void>
  68. {
  69. typedef nat &type;
  70. };
  71. template<>
  72. struct add_reference<const void>
  73. {
  74. typedef const nat &type;
  75. };
  76. template <class T>
  77. struct add_const_reference
  78. { typedef const T &type; };
  79. template <class T>
  80. struct add_const_reference<T&>
  81. { typedef T& type; };
  82. template<class T>
  83. struct remove_const
  84. {
  85. typedef T type;
  86. };
  87. template<class T>
  88. struct remove_const<const T>
  89. {
  90. typedef T type;
  91. };
  92. template<class T>
  93. struct remove_volatile
  94. {
  95. typedef T type;
  96. };
  97. template<class T>
  98. struct remove_volatile<volatile T>
  99. {
  100. typedef T type;
  101. };
  102. template<class T>
  103. struct remove_const_volatile
  104. {
  105. typedef typename remove_const<typename remove_volatile<T>::type>::type type;
  106. };
  107. template <typename T, typename U>
  108. struct is_same
  109. {
  110. typedef char yes_type;
  111. struct no_type
  112. {
  113. char padding[8];
  114. };
  115. template <typename V>
  116. static yes_type is_same_tester(V*, V*);
  117. static no_type is_same_tester(...);
  118. static T *t;
  119. static U *u;
  120. static const bool value = sizeof(yes_type) == sizeof(is_same_tester(t,u));
  121. };
  122. template<class T, class U>
  123. struct is_cv_same
  124. {
  125. static const bool value = is_same< typename remove_const_volatile<T>::type
  126. , typename remove_const_volatile<U>::type >::value;
  127. };
  128. } // namespace ipcdetail
  129. } //namespace interprocess {
  130. } //namespace boost {
  131. #include <boost/interprocess/detail/config_end.hpp>
  132. #endif //#ifndef BOOST_INTERPROCESS_DETAIL_TYPE_TRAITS_HPP