blob: 76baf11943f9610e1c8f0e3c469db84a362da141 [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070010#ifndef NDNBOOST_TT_IS_UNSIGNED_HPP_INCLUDED
11#define NDNBOOST_TT_IS_UNSIGNED_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -070012
13#include <ndnboost/type_traits/is_integral.hpp>
14#include <ndnboost/type_traits/is_enum.hpp>
15#include <ndnboost/type_traits/remove_cv.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
21namespace ndnboost {
22
23#if !defined( __CODEGEARC__ )
24
25namespace detail{
26
Jeff Thompson3d613fd2013-10-15 15:39:04 -070027#if !(defined(__EDG_VERSION__) && __EDG_VERSION__ <= 238) && !defined(NDNBOOST_NO_INCLASS_MEMBER_INITIALIZATION)
Jeff Thompsona28eed82013-08-22 16:21:10 -070028
29template <class T>
30struct is_unsigned_values
31{
32 //
Jeff Thompson3d613fd2013-10-15 15:39:04 -070033 // Note that we cannot use NDNBOOST_STATIC_CONSTANT here, using enum's
Jeff Thompsona28eed82013-08-22 16:21:10 -070034 // 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{
Jeff Thompson3d613fd2013-10-15 15:39:04 -070045 NDNBOOST_STATIC_CONSTANT(bool, value = (::ndnboost::detail::is_unsigned_values<T>::minus_one > ::ndnboost::detail::is_unsigned_values<T>::zero));
Jeff Thompsona28eed82013-08-22 16:21:10 -070046};
47
48template <bool integral_type>
49struct is_ununsigned_select_helper
50{
51 template <class T>
52 struct rebind
53 {
54 typedef is_ununsigned_helper<T> type;
55 };
56};
57
58template <>
59struct is_ununsigned_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_imp
70{
71 typedef is_ununsigned_select_helper<
72 ::ndnboost::type_traits::ice_or<
73 ::ndnboost::is_integral<T>::value,
74 ::ndnboost::is_enum<T>::value>::value
75 > selector;
76 typedef typename selector::template rebind<T> binder;
77 typedef typename binder::type type;
Jeff Thompson3d613fd2013-10-15 15:39:04 -070078 NDNBOOST_STATIC_CONSTANT(bool, value = type::value);
Jeff Thompsona28eed82013-08-22 16:21:10 -070079};
80
81#else
82
83template <class T> struct is_unsigned_imp : public false_type{};
84template <> struct is_unsigned_imp<unsigned char> : public true_type{};
85template <> struct is_unsigned_imp<const unsigned char> : public true_type{};
86template <> struct is_unsigned_imp<volatile unsigned char> : public true_type{};
87template <> struct is_unsigned_imp<const volatile unsigned char> : public true_type{};
88template <> struct is_unsigned_imp<unsigned short> : public true_type{};
89template <> struct is_unsigned_imp<const unsigned short> : public true_type{};
90template <> struct is_unsigned_imp<volatile unsigned short> : public true_type{};
91template <> struct is_unsigned_imp<const volatile unsigned short> : public true_type{};
92template <> struct is_unsigned_imp<unsigned int> : public true_type{};
93template <> struct is_unsigned_imp<const unsigned int> : public true_type{};
94template <> struct is_unsigned_imp<volatile unsigned int> : public true_type{};
95template <> struct is_unsigned_imp<const volatile unsigned int> : public true_type{};
96template <> struct is_unsigned_imp<unsigned long> : public true_type{};
97template <> struct is_unsigned_imp<const unsigned long> : public true_type{};
98template <> struct is_unsigned_imp<volatile unsigned long> : public true_type{};
99template <> struct is_unsigned_imp<const volatile unsigned long> : public true_type{};
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700100#ifdef NDNBOOST_HAS_LONG_LONG
Jeff Thompsona28eed82013-08-22 16:21:10 -0700101template <> struct is_unsigned_imp<unsigned long long> : public true_type{};
102template <> struct is_unsigned_imp<const unsigned long long> : public true_type{};
103template <> struct is_unsigned_imp<volatile unsigned long long> : public true_type{};
104template <> struct is_unsigned_imp<const volatile unsigned long long> : public true_type{};
105#endif
106#if defined(CHAR_MIN) && (CHAR_MIN == 0)
107template <> struct is_unsigned_imp<char> : public true_type{};
108template <> struct is_unsigned_imp<const char> : public true_type{};
109template <> struct is_unsigned_imp<volatile char> : public true_type{};
110template <> struct is_unsigned_imp<const volatile char> : public true_type{};
111#endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700112#if defined(WCHAR_MIN) && (WCHAR_MIN == 0) && !defined(NDNBOOST_NO_INTRINSIC_WCHAR_T)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700113template <> struct is_unsigned_imp<wchar_t> : public true_type{};
114template <> struct is_unsigned_imp<const wchar_t> : public true_type{};
115template <> struct is_unsigned_imp<volatile wchar_t> : public true_type{};
116template <> struct is_unsigned_imp<const volatile wchar_t> : public true_type{};
117#endif
118
119#endif
120
121}
122
123#endif // !defined( __CODEGEARC__ )
124
125#if defined( __CODEGEARC__ )
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700126NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(is_unsigned,T,__is_unsigned(T))
Jeff Thompsona28eed82013-08-22 16:21:10 -0700127#else
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700128NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(is_unsigned,T,::ndnboost::detail::is_unsigned_imp<T>::value)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700129#endif
130
131} // namespace ndnboost
132
133#include <ndnboost/type_traits/detail/bool_trait_undef.hpp>
134
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700135#endif // NDNBOOST_TT_IS_MEMBER_FUNCTION_POINTER_HPP_INCLUDED