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