is_unsigned.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // (C) Copyright John Maddock 2005.
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. //
  6. // See http://www.boost.org/libs/type_traits for most recent version including documentation.
  7. #ifndef BOOST_TT_IS_UNSIGNED_HPP_INCLUDED
  8. #define BOOST_TT_IS_UNSIGNED_HPP_INCLUDED
  9. #include <boost/type_traits/is_integral.hpp>
  10. #include <boost/type_traits/is_enum.hpp>
  11. #include <boost/type_traits/remove_cv.hpp>
  12. #include <climits>
  13. namespace boost {
  14. #if !defined( __CODEGEARC__ )
  15. #if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1310) &&\
  16. !(defined(__EDG_VERSION__) && __EDG_VERSION__ <= 238) &&\
  17. !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)
  18. namespace detail{
  19. template <class T>
  20. struct is_unsigned_values
  21. {
  22. //
  23. // Note that we cannot use BOOST_STATIC_CONSTANT here, using enum's
  24. // rather than "real" static constants simply doesn't work or give
  25. // the correct answer.
  26. //
  27. typedef typename remove_cv<T>::type no_cv_t;
  28. static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
  29. static const no_cv_t zero = (static_cast<no_cv_t>(0));
  30. };
  31. template <class T>
  32. struct is_ununsigned_helper
  33. {
  34. BOOST_STATIC_CONSTANT(bool, value = (::boost::detail::is_unsigned_values<T>::minus_one > ::boost::detail::is_unsigned_values<T>::zero));
  35. };
  36. template <bool integral_type>
  37. struct is_unsigned_select_helper
  38. {
  39. template <class T>
  40. struct rebind
  41. {
  42. typedef is_ununsigned_helper<T> type;
  43. };
  44. };
  45. template <>
  46. struct is_unsigned_select_helper<false>
  47. {
  48. template <class T>
  49. struct rebind
  50. {
  51. typedef false_type type;
  52. };
  53. };
  54. template <class T>
  55. struct is_unsigned
  56. {
  57. typedef ::boost::detail::is_unsigned_select_helper< ::boost::is_integral<T>::value || ::boost::is_enum<T>::value > selector;
  58. typedef typename selector::template rebind<T> binder;
  59. typedef typename binder::type type;
  60. BOOST_STATIC_CONSTANT(bool, value = type::value);
  61. };
  62. } // namespace detail
  63. template <class T> struct is_unsigned : public integral_constant<bool, boost::detail::is_unsigned<T>::value> {};
  64. #else
  65. template <class T> struct is_unsigned : public false_type{};
  66. #endif
  67. #else // defined( __CODEGEARC__ )
  68. template <class T> struct is_unsigned : public integral_constant<bool, __is_unsigned(T)> {};
  69. #endif
  70. template <> struct is_unsigned<unsigned char> : public true_type{};
  71. template <> struct is_unsigned<const unsigned char> : public true_type{};
  72. template <> struct is_unsigned<volatile unsigned char> : public true_type{};
  73. template <> struct is_unsigned<const volatile unsigned char> : public true_type{};
  74. template <> struct is_unsigned<unsigned short> : public true_type{};
  75. template <> struct is_unsigned<const unsigned short> : public true_type{};
  76. template <> struct is_unsigned<volatile unsigned short> : public true_type{};
  77. template <> struct is_unsigned<const volatile unsigned short> : public true_type{};
  78. template <> struct is_unsigned<unsigned int> : public true_type{};
  79. template <> struct is_unsigned<const unsigned int> : public true_type{};
  80. template <> struct is_unsigned<volatile unsigned int> : public true_type{};
  81. template <> struct is_unsigned<const volatile unsigned int> : public true_type{};
  82. template <> struct is_unsigned<unsigned long> : public true_type{};
  83. template <> struct is_unsigned<const unsigned long> : public true_type{};
  84. template <> struct is_unsigned<volatile unsigned long> : public true_type{};
  85. template <> struct is_unsigned<const volatile unsigned long> : public true_type{};
  86. template <> struct is_unsigned<signed char> : public false_type{};
  87. template <> struct is_unsigned<const signed char> : public false_type{};
  88. template <> struct is_unsigned<volatile signed char> : public false_type{};
  89. template <> struct is_unsigned<const volatile signed char> : public false_type{};
  90. template <> struct is_unsigned< short> : public false_type{};
  91. template <> struct is_unsigned<const short> : public false_type{};
  92. template <> struct is_unsigned<volatile short> : public false_type{};
  93. template <> struct is_unsigned<const volatile short> : public false_type{};
  94. template <> struct is_unsigned< int> : public false_type{};
  95. template <> struct is_unsigned<const int> : public false_type{};
  96. template <> struct is_unsigned<volatile int> : public false_type{};
  97. template <> struct is_unsigned<const volatile int> : public false_type{};
  98. template <> struct is_unsigned< long> : public false_type{};
  99. template <> struct is_unsigned<const long> : public false_type{};
  100. template <> struct is_unsigned<volatile long> : public false_type{};
  101. template <> struct is_unsigned<const volatile long> : public false_type{};
  102. #ifdef BOOST_HAS_LONG_LONG
  103. template <> struct is_unsigned< ::boost::ulong_long_type> : public true_type{};
  104. template <> struct is_unsigned<const ::boost::ulong_long_type> : public true_type{};
  105. template <> struct is_unsigned<volatile ::boost::ulong_long_type> : public true_type{};
  106. template <> struct is_unsigned<const volatile ::boost::ulong_long_type> : public true_type{};
  107. template <> struct is_unsigned< ::boost::long_long_type> : public false_type{};
  108. template <> struct is_unsigned<const ::boost::long_long_type> : public false_type{};
  109. template <> struct is_unsigned<volatile ::boost::long_long_type> : public false_type{};
  110. template <> struct is_unsigned<const volatile ::boost::long_long_type> : public false_type{};
  111. #endif
  112. #if defined(CHAR_MIN)
  113. #if CHAR_MIN == 0
  114. template <> struct is_unsigned<char> : public true_type{};
  115. template <> struct is_unsigned<const char> : public true_type{};
  116. template <> struct is_unsigned<volatile char> : public true_type{};
  117. template <> struct is_unsigned<const volatile char> : public true_type{};
  118. #else
  119. template <> struct is_unsigned<char> : public false_type{};
  120. template <> struct is_unsigned<const char> : public false_type{};
  121. template <> struct is_unsigned<volatile char> : public false_type{};
  122. template <> struct is_unsigned<const volatile char> : public false_type{};
  123. #endif
  124. #endif
  125. #if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && defined(WCHAR_MIN)
  126. #if WCHAR_MIN == 0
  127. template <> struct is_unsigned<wchar_t> : public true_type{};
  128. template <> struct is_unsigned<const wchar_t> : public true_type{};
  129. template <> struct is_unsigned<volatile wchar_t> : public true_type{};
  130. template <> struct is_unsigned<const volatile wchar_t> : public true_type{};
  131. #else
  132. template <> struct is_unsigned<wchar_t> : public false_type{};
  133. template <> struct is_unsigned<const wchar_t> : public false_type{};
  134. template <> struct is_unsigned<volatile wchar_t> : public false_type{};
  135. template <> struct is_unsigned<const volatile wchar_t> : public false_type{};
  136. #endif
  137. #endif
  138. } // namespace boost
  139. #endif // BOOST_TT_IS_MEMBER_FUNCTION_POINTER_HPP_INCLUDED