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_UNSIGNED_HPP_INCLUDED
11#define BOOST_TT_IS_UNSIGNED_HPP_INCLUDED
12
13#include <boost/type_traits/is_integral.hpp>
14#include <boost/type_traits/is_enum.hpp>
15#include <boost/type_traits/remove_cv.hpp>
16
17#include <climits>
18
19namespace boost {
20
21#if !defined( __CODEGEARC__ )
22
23#if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1310) &&\
24 !(defined(__EDG_VERSION__) && __EDG_VERSION__ <= 238) &&\
25 !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)
26
27namespace detail{
28
29template <class T>
30struct is_unsigned_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
42template <class T>
43struct is_ununsigned_helper
44{
45 BOOST_STATIC_CONSTANT(bool, value = (::boost::detail::is_unsigned_values<T>::minus_one > ::boost::detail::is_unsigned_values<T>::zero));
46};
47
48template <bool integral_type>
49struct is_unsigned_select_helper
50{
51 template <class T>
52 struct rebind
53 {
54 typedef is_ununsigned_helper<T> type;
55 };
56};
57
58template <>
59struct is_unsigned_select_helper<false>
60{
61 template <class T>
62 struct rebind
63 {
64 typedef false_type type;
65 };
66};
67
68template <class T>
69struct is_unsigned
70{
71 typedef ::boost::detail::is_unsigned_select_helper< ::boost::is_integral<T>::value || ::boost::is_enum<T>::value > selector;
72 typedef typename selector::template rebind<T> binder;
73 typedef typename binder::type type;
74 BOOST_STATIC_CONSTANT(bool, value = type::value);
75};
76
77} // namespace detail
78
79template <class T> struct is_unsigned : public integral_constant<bool, boost::detail::is_unsigned<T>::value> {};
80
81#else
82
83template <class T> struct is_unsigned : public false_type{};
84
85#endif
86
87#else // defined( __CODEGEARC__ )
88template <class T> struct is_unsigned : public integral_constant<bool, __is_unsigned(T)> {};
89#endif
90
91template <> struct is_unsigned<unsigned char> : public true_type{};
92template <> struct is_unsigned<const unsigned char> : public true_type{};
93template <> struct is_unsigned<volatile unsigned char> : public true_type{};
94template <> struct is_unsigned<const volatile unsigned char> : public true_type{};
95template <> struct is_unsigned<unsigned short> : public true_type{};
96template <> struct is_unsigned<const unsigned short> : public true_type{};
97template <> struct is_unsigned<volatile unsigned short> : public true_type{};
98template <> struct is_unsigned<const volatile unsigned short> : public true_type{};
99template <> struct is_unsigned<unsigned int> : public true_type{};
100template <> struct is_unsigned<const unsigned int> : public true_type{};
101template <> struct is_unsigned<volatile unsigned int> : public true_type{};
102template <> struct is_unsigned<const volatile unsigned int> : public true_type{};
103template <> struct is_unsigned<unsigned long> : public true_type{};
104template <> struct is_unsigned<const unsigned long> : public true_type{};
105template <> struct is_unsigned<volatile unsigned long> : public true_type{};
106template <> struct is_unsigned<const volatile unsigned long> : public true_type{};
107
108template <> struct is_unsigned<signed char> : public false_type{};
109template <> struct is_unsigned<const signed char> : public false_type{};
110template <> struct is_unsigned<volatile signed char> : public false_type{};
111template <> struct is_unsigned<const volatile signed char> : public false_type{};
112template <> struct is_unsigned< short> : public false_type{};
113template <> struct is_unsigned<const short> : public false_type{};
114template <> struct is_unsigned<volatile short> : public false_type{};
115template <> struct is_unsigned<const volatile short> : public false_type{};
116template <> struct is_unsigned< int> : public false_type{};
117template <> struct is_unsigned<const int> : public false_type{};
118template <> struct is_unsigned<volatile int> : public false_type{};
119template <> struct is_unsigned<const volatile int> : public false_type{};
120template <> struct is_unsigned< long> : public false_type{};
121template <> struct is_unsigned<const long> : public false_type{};
122template <> struct is_unsigned<volatile long> : public false_type{};
123template <> struct is_unsigned<const volatile long> : public false_type{};
124#ifdef BOOST_HAS_LONG_LONG
125template <> struct is_unsigned< ::boost::ulong_long_type> : public true_type{};
126template <> struct is_unsigned<const ::boost::ulong_long_type> : public true_type{};
127template <> struct is_unsigned<volatile ::boost::ulong_long_type> : public true_type{};
128template <> struct is_unsigned<const volatile ::boost::ulong_long_type> : public true_type{};
129
130template <> struct is_unsigned< ::boost::long_long_type> : public false_type{};
131template <> struct is_unsigned<const ::boost::long_long_type> : public false_type{};
132template <> struct is_unsigned<volatile ::boost::long_long_type> : public false_type{};
133template <> struct is_unsigned<const volatile ::boost::long_long_type> : public false_type{};
134#endif
135#if defined(CHAR_MIN)
136#if CHAR_MIN == 0
137template <> struct is_unsigned<char> : public true_type{};
138template <> struct is_unsigned<const char> : public true_type{};
139template <> struct is_unsigned<volatile char> : public true_type{};
140template <> struct is_unsigned<const volatile char> : public true_type{};
141#else
142template <> struct is_unsigned<char> : public false_type{};
143template <> struct is_unsigned<const char> : public false_type{};
144template <> struct is_unsigned<volatile char> : public false_type{};
145template <> struct is_unsigned<const volatile char> : public false_type{};
146#endif
147#endif
148#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) && defined(WCHAR_MIN)
149#if WCHAR_MIN == 0
150template <> struct is_unsigned<wchar_t> : public true_type{};
151template <> struct is_unsigned<const wchar_t> : public true_type{};
152template <> struct is_unsigned<volatile wchar_t> : public true_type{};
153template <> struct is_unsigned<const volatile wchar_t> : public true_type{};
154#else
155template <> struct is_unsigned<wchar_t> : public false_type{};
156template <> struct is_unsigned<const wchar_t> : public false_type{};
157template <> struct is_unsigned<volatile wchar_t> : public false_type{};
158template <> struct is_unsigned<const volatile wchar_t> : public false_type{};
159#endif
160#endif
161} // namespace boost
162
163#endif // BOOST_TT_IS_MEMBER_FUNCTION_POINTER_HPP_INCLUDED
164