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