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