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).
7 // See http://www.boost.org/libs/type_traits for most recent version including documentation.
9 #ifndef BOOST_TT_MAKE_UNSIGNED_HPP_INCLUDED
10 #define BOOST_TT_MAKE_UNSIGNED_HPP_INCLUDED
12 #include <boost/type_traits/conditional.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/static_assert.hpp>
31 BOOST_STATIC_ASSERT_MSG((::boost::is_integral<T>::value || ::boost::is_enum<T>::value), "The template argument to make_unsigned must be an integer or enum type.");
32 BOOST_STATIC_ASSERT_MSG((! ::boost::is_same<typename remove_cv<T>::type, bool>::value), "The template argument to make_unsigned must not be the type bool");
34 typedef typename remove_cv<T>::type t_no_cv;
35 typedef typename conditional<
36 (::boost::is_unsigned<T>::value && ::boost::is_integral<T>::value
37 && ! ::boost::is_same<t_no_cv, char>::value
38 && ! ::boost::is_same<t_no_cv, wchar_t>::value
39 && ! ::boost::is_same<t_no_cv, bool>::value),
42 (::boost::is_integral<T>::value
43 && ! ::boost::is_same<t_no_cv, char>::value
44 && ! ::boost::is_same<t_no_cv, wchar_t>::value
45 && ! ::boost::is_same<t_no_cv, bool>::value),
47 is_same<t_no_cv, signed char>::value,
50 is_same<t_no_cv, short>::value,
53 is_same<t_no_cv, int>::value,
56 is_same<t_no_cv, long>::value,
58 #if defined(BOOST_HAS_LONG_LONG)
59 #ifdef BOOST_HAS_INT128
61 sizeof(t_no_cv) == sizeof(boost::ulong_long_type),
62 boost::ulong_long_type,
66 boost::ulong_long_type
68 #elif defined(BOOST_HAS_MS_INT64)
77 // Not a regular integer type:
79 sizeof(t_no_cv) == sizeof(unsigned char),
82 sizeof(t_no_cv) == sizeof(unsigned short),
85 sizeof(t_no_cv) == sizeof(unsigned int),
88 sizeof(t_no_cv) == sizeof(unsigned long),
90 #if defined(BOOST_HAS_LONG_LONG)
91 #ifdef BOOST_HAS_INT128
93 sizeof(t_no_cv) == sizeof(boost::ulong_long_type),
94 boost::ulong_long_type,
98 boost::ulong_long_type
100 #elif defined(BOOST_HAS_MS_INT64)
110 >::type base_integer_type;
112 // Add back any const qualifier:
113 typedef typename conditional<
115 typename add_const<base_integer_type>::type,
117 >::type const_base_integer_type;
119 // Add back any volatile qualifier:
120 typedef typename conditional<
121 is_volatile<T>::value,
122 typename add_volatile<const_base_integer_type>::type,
123 const_base_integer_type
129 #endif // BOOST_TT_ADD_REFERENCE_HPP_INCLUDED