/Src/Dependencies/Boost/boost/interprocess/detail/type_traits.hpp

http://hadesmem.googlecode.com/ · C++ Header · 166 lines · 120 code · 30 blank · 16 comment · 2 complexity · 1a3e2e5e9107bcbac90b319c1bb41483 MD5 · raw file

  1. //////////////////////////////////////////////////////////////////////////////
  2. // (C) Copyright John Maddock 2000.
  3. // (C) Copyright Ion Gaztanaga 2005-2009.
  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. // The alignment_of implementation comes from John Maddock's boost::alignment_of code
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #ifndef BOOST_INTERPROCESS_DETAIL_TYPE_TRAITS_HPP
  15. #define BOOST_INTERPROCESS_DETAIL_TYPE_TRAITS_HPP
  16. #if (defined _MSC_VER) && (_MSC_VER >= 1200)
  17. # pragma once
  18. #endif
  19. #include <boost/interprocess/detail/config_begin.hpp>
  20. namespace boost {
  21. namespace interprocess {
  22. namespace detail {
  23. struct nat{};
  24. //boost::alignment_of yields to 10K lines of preprocessed code, so we
  25. //need an alternative
  26. template <typename T> struct alignment_of;
  27. template <typename T>
  28. struct alignment_of_hack
  29. {
  30. char c;
  31. T t;
  32. alignment_of_hack();
  33. };
  34. template <unsigned A, unsigned S>
  35. struct alignment_logic
  36. {
  37. enum{ value = A < S ? A : S };
  38. };
  39. template< typename T >
  40. struct alignment_of
  41. {
  42. enum{ value = alignment_logic
  43. < sizeof(alignment_of_hack<T>) - sizeof(T)
  44. , sizeof(T)>::value };
  45. };
  46. //This is not standard, but should work with all compilers
  47. union max_align
  48. {
  49. char char_;
  50. short short_;
  51. int int_;
  52. long long_;
  53. #ifdef BOOST_HAS_LONG_LONG
  54. long long long_long_;
  55. #endif
  56. float float_;
  57. double double_;
  58. long double long_double_;
  59. void * void_ptr_;
  60. };
  61. template<class T>
  62. struct remove_reference
  63. {
  64. typedef T type;
  65. };
  66. template<class T>
  67. struct remove_reference<T&>
  68. {
  69. typedef T type;
  70. };
  71. template<class T>
  72. struct is_reference
  73. {
  74. enum { value = false };
  75. };
  76. template<class T>
  77. struct is_reference<T&>
  78. {
  79. enum { value = true };
  80. };
  81. template<class T>
  82. struct is_pointer
  83. {
  84. enum { value = false };
  85. };
  86. template<class T>
  87. struct is_pointer<T*>
  88. {
  89. enum { value = true };
  90. };
  91. template <typename T>
  92. struct add_reference
  93. {
  94. typedef T& type;
  95. };
  96. template<class T>
  97. struct add_reference<T&>
  98. {
  99. typedef T& type;
  100. };
  101. template<>
  102. struct add_reference<void>
  103. {
  104. typedef nat &type;
  105. };
  106. template<>
  107. struct add_reference<const void>
  108. {
  109. typedef const nat &type;
  110. };
  111. template <class T>
  112. struct add_const_reference
  113. { typedef const T &type; };
  114. template <class T>
  115. struct add_const_reference<T&>
  116. { typedef T& type; };
  117. template <typename T, typename U>
  118. struct is_same
  119. {
  120. typedef char yes_type;
  121. struct no_type
  122. {
  123. char padding[8];
  124. };
  125. template <typename V>
  126. static yes_type is_same_tester(V*, V*);
  127. static no_type is_same_tester(...);
  128. static T *t;
  129. static U *u;
  130. static const bool value = sizeof(yes_type) == sizeof(is_same_tester(t,u));
  131. };
  132. } // namespace detail
  133. } //namespace interprocess {
  134. } //namespace boost {
  135. #endif //#ifndef BOOST_INTERPROCESS_DETAIL_TYPE_TRAITS_HPP
  136. #include <boost/interprocess/detail/config_end.hpp>