1
2// (C) Copyright John Maddock 2007.
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#ifndef BOOST_TT_MAKE_UNSIGNED_HPP_INCLUDED
10#define BOOST_TT_MAKE_UNSIGNED_HPP_INCLUDED
11
12#include <boost/mpl/if.hpp>
13#include <boost/type_traits/is_integral.hpp>
14#include <boost/type_traits/is_signed.hpp>
15#include <boost/type_traits/is_unsigned.hpp>
16#include <boost/type_traits/is_enum.hpp>
17#include <boost/type_traits/is_same.hpp>
18#include <boost/type_traits/remove_cv.hpp>
19#include <boost/type_traits/is_const.hpp>
20#include <boost/type_traits/is_volatile.hpp>
21#include <boost/type_traits/add_const.hpp>
22#include <boost/type_traits/add_volatile.hpp>
23#include <boost/type_traits/detail/ice_or.hpp>
24#include <boost/type_traits/detail/ice_and.hpp>
25#include <boost/type_traits/detail/ice_not.hpp>
26#include <boost/static_assert.hpp>
27
28// should be the last #include
29#include <boost/type_traits/detail/type_trait_def.hpp>
30
31namespace boost {
32
33namespace detail {
34
35template <class T>
36struct make_unsigned_imp
37{
38 BOOST_STATIC_ASSERT(
39 (::boost::type_traits::ice_or< ::boost::is_integral<T>::value, ::boost::is_enum<T>::value>::value));
40 BOOST_STATIC_ASSERT(
41 (::boost::type_traits::ice_not< ::boost::is_same<
42 typename remove_cv<T>::type, bool>::value>::value));
43
44 typedef typename remove_cv<T>::type t_no_cv;
45 typedef typename mpl::if_c<
46 (::boost::type_traits::ice_and<
47 ::boost::is_unsigned<T>::value,
48 ::boost::is_integral<T>::value,
49 ::boost::type_traits::ice_not< ::boost::is_same<t_no_cv, char>::value>::value,
50 ::boost::type_traits::ice_not< ::boost::is_same<t_no_cv, wchar_t>::value>::value,
51 ::boost::type_traits::ice_not< ::boost::is_same<t_no_cv, bool>::value>::value >::value),
52 T,
53 typename mpl::if_c<
54 (::boost::type_traits::ice_and<
55 ::boost::is_integral<T>::value,
56 ::boost::type_traits::ice_not< ::boost::is_same<t_no_cv, char>::value>::value,
57 ::boost::type_traits::ice_not< ::boost::is_same<t_no_cv, wchar_t>::value>::value,
58 ::boost::type_traits::ice_not< ::boost::is_same<t_no_cv, bool>::value>::value>
59 ::value),
60 typename mpl::if_<
61 is_same<t_no_cv, signed char>,
62 unsigned char,
63 typename mpl::if_<
64 is_same<t_no_cv, short>,
65 unsigned short,
66 typename mpl::if_<
67 is_same<t_no_cv, int>,
68 unsigned int,
69 typename mpl::if_<
70 is_same<t_no_cv, long>,
71 unsigned long,
72#if defined(BOOST_HAS_LONG_LONG)
73#ifdef BOOST_HAS_INT128
74 typename mpl::if_c<
75 sizeof(t_no_cv) == sizeof(boost::ulong_long_type),
76 boost::ulong_long_type,
77 boost::uint128_type
78 >::type
79#else
80 boost::ulong_long_type
81#endif
82#elif defined(BOOST_HAS_MS_INT64)
83 unsigned __int64
84#else
85 unsigned long
86#endif
87 >::type
88 >::type
89 >::type
90 >::type,
91 // Not a regular integer type:
92 typename mpl::if_c<
93 sizeof(t_no_cv) == sizeof(unsigned char),
94 unsigned char,
95 typename mpl::if_c<
96 sizeof(t_no_cv) == sizeof(unsigned short),
97 unsigned short,
98 typename mpl::if_c<
99 sizeof(t_no_cv) == sizeof(unsigned int),
100 unsigned int,
101 typename mpl::if_c<
102 sizeof(t_no_cv) == sizeof(unsigned long),
103 unsigned long,
104#if defined(BOOST_HAS_LONG_LONG)
105#ifdef BOOST_HAS_INT128
106 typename mpl::if_c<
107 sizeof(t_no_cv) == sizeof(boost::ulong_long_type),
108 boost::ulong_long_type,
109 boost::uint128_type
110 >::type
111#else
112 boost::ulong_long_type
113#endif
114#elif defined(BOOST_HAS_MS_INT64)
115 unsigned __int64
116#else
117 unsigned long
118#endif
119 >::type
120 >::type
121 >::type
122 >::type
123 >::type
124 >::type base_integer_type;
125
126 // Add back any const qualifier:
127 typedef typename mpl::if_<
128 is_const<T>,
129 typename add_const<base_integer_type>::type,
130 base_integer_type
131 >::type const_base_integer_type;
132
133 // Add back any volatile qualifier:
134 typedef typename mpl::if_<
135 is_volatile<T>,
136 typename add_volatile<const_base_integer_type>::type,
137 const_base_integer_type
138 >::type type;
139};
140
141
142} // namespace detail
143
144BOOST_TT_AUX_TYPE_TRAIT_DEF1(make_unsigned,T,typename boost::detail::make_unsigned_imp<T>::type)
145
146} // namespace boost
147
148#include <boost/type_traits/detail/type_trait_undef.hpp>
149
150#endif // BOOST_TT_ADD_REFERENCE_HPP_INCLUDED
151
152