@@ -37,10 +37,11 @@ namespace chip {
37
37
template <typename T, typename U, std::enable_if_t <std::is_integral<T>::value, int > = 0 >
38
38
bool CanCastTo (U arg)
39
39
{
40
+ using namespace std ;
40
41
// U might be a reference to an integer type, if we're assigning from
41
42
// something passed by reference.
42
- typedef typename std:: remove_reference<U>::type V; // V for "value"
43
- static_assert (std:: is_integral<V>::value, " Must be assigning from an integral type" );
43
+ typedef typename remove_reference<U>::type V; // V for "value"
44
+ static_assert (is_integral<V>::value, " Must be assigning from an integral type" );
44
45
45
46
// We want to check that "arg" can fit inside T but without doing any tests
46
47
// that are always true or always false due to the types involved, which
@@ -63,44 +64,44 @@ bool CanCastTo(U arg)
63
64
// of T and V is signed and the other is unsigned: there might not be a
64
65
// single integer type that can represent _both_ the value of arg and the
65
66
// minimal/maximal value.
66
- if (std:: numeric_limits<T>::is_signed && std:: numeric_limits<V>::is_signed)
67
+ if (numeric_limits<T>::is_signed && numeric_limits<V>::is_signed)
67
68
{
68
- if (static_cast <intmax_t >(std:: numeric_limits<V>::max ()) <= static_cast <intmax_t >(std:: numeric_limits<T>::max ()) &&
69
- static_cast <intmax_t >(std:: numeric_limits<V>::min ()) >= static_cast <intmax_t >(std:: numeric_limits<T>::min ()))
69
+ if (static_cast <intmax_t >(numeric_limits<V>::max ()) <= static_cast <intmax_t >(numeric_limits<T>::max ()) &&
70
+ static_cast <intmax_t >(numeric_limits<V>::min ()) >= static_cast <intmax_t >(numeric_limits<T>::min ()))
70
71
{
71
72
// Any checks on arg would be trivially true; don't even do them, to
72
73
// avoid warnings.
73
74
return true ;
74
75
}
75
76
76
- return static_cast <intmax_t >(std:: numeric_limits<T>::min ()) <= static_cast <intmax_t >(arg) &&
77
- static_cast <intmax_t >(arg) <= static_cast <intmax_t >(std:: numeric_limits<T>::max ());
77
+ return static_cast <intmax_t >(numeric_limits<T>::min ()) <= static_cast <intmax_t >(arg) &&
78
+ static_cast <intmax_t >(arg) <= static_cast <intmax_t >(numeric_limits<T>::max ());
78
79
}
79
80
80
- if (!std:: numeric_limits<T>::is_signed && !std:: numeric_limits<V>::is_signed)
81
+ if (!numeric_limits<T>::is_signed && !numeric_limits<V>::is_signed)
81
82
{
82
- if (static_cast <uintmax_t >(std:: numeric_limits<V>::max ()) <= static_cast <uintmax_t >(std:: numeric_limits<T>::max ()))
83
+ if (static_cast <uintmax_t >(numeric_limits<V>::max ()) <= static_cast <uintmax_t >(numeric_limits<T>::max ()))
83
84
{
84
85
// Any checks on arg would be trivially true; don't even do them, to
85
86
// avoid warnings.
86
87
return true ;
87
88
}
88
89
89
- return static_cast <uintmax_t >(arg) <= static_cast <uintmax_t >(std:: numeric_limits<T>::max ());
90
+ return static_cast <uintmax_t >(arg) <= static_cast <uintmax_t >(numeric_limits<T>::max ());
90
91
}
91
92
92
- if (std:: numeric_limits<T>::is_signed)
93
+ if (numeric_limits<T>::is_signed)
93
94
{
94
- static_assert (std:: numeric_limits<T>::max () >= 0 , " What weird type is this?" );
95
- if (static_cast <uintmax_t >(std:: numeric_limits<V>::max ()) <= static_cast <uintmax_t >(std:: numeric_limits<T>::max ()))
95
+ static_assert (numeric_limits<T>::max () >= 0 , " What weird type is this?" );
96
+ if (static_cast <uintmax_t >(numeric_limits<V>::max ()) <= static_cast <uintmax_t >(numeric_limits<T>::max ()))
96
97
{
97
98
return true ;
98
99
}
99
100
100
- return static_cast <uintmax_t >(arg) <= static_cast <uintmax_t >(std:: numeric_limits<T>::max ());
101
+ return static_cast <uintmax_t >(arg) <= static_cast <uintmax_t >(numeric_limits<T>::max ());
101
102
}
102
103
103
- return 0 <= arg && static_cast <uintmax_t >(arg) <= static_cast <uintmax_t >(std:: numeric_limits<T>::max ());
104
+ return 0 <= arg && static_cast <uintmax_t >(arg) <= static_cast <uintmax_t >(numeric_limits<T>::max ());
104
105
}
105
106
106
107
template <typename T, typename U, std::enable_if_t <std::is_enum<T>::value, int > = 0 >
@@ -126,9 +127,10 @@ bool CanCastTo(U arg)
126
127
template <typename T>
127
128
typename std::enable_if<std::is_unsigned<T>::value, typename std::make_signed<T>::type>::type CastToSigned (T arg)
128
129
{
129
- typedef typename std::make_signed<T>::type signed_type;
130
+ using namespace std ;
131
+ typedef typename make_signed<T>::type signed_type;
130
132
131
- if (arg <= static_cast <T>(std:: numeric_limits<signed_type>::max ()))
133
+ if (arg <= static_cast <T>(numeric_limits<signed_type>::max ()))
132
134
{
133
135
return static_cast <signed_type>(arg);
134
136
}
@@ -140,7 +142,7 @@ typename std::enable_if<std::is_unsigned<T>::value, typename std::make_signed<T>
140
142
//
141
143
// then noting that both (numeric_limits<T>::max() - arg) and its negation
142
144
// are guaranteed to fit in signed_type.
143
- signed_type diff = static_cast <signed_type>(std:: numeric_limits<T>::max () - arg);
145
+ signed_type diff = static_cast <signed_type>(numeric_limits<T>::max () - arg);
144
146
return static_cast <signed_type>(-diff - 1 );
145
147
}
146
148
0 commit comments