30 #ifndef _GLIBCXX_PARSE_NUMBERS_H 31 #define _GLIBCXX_PARSE_NUMBERS_H 1 33 #pragma GCC system_header 37 #if __cplusplus > 201103L 41 namespace std _GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
47 template<
unsigned _Base,
char _Dig>
50 template<
unsigned _Base>
51 struct _Digit<_Base, '0'> : integral_constant<unsigned, 0>
56 template<
unsigned _Base>
57 struct _Digit<_Base, '1'> : integral_constant<unsigned, 1>
62 template<
unsigned _Base,
unsigned _Val>
63 struct _Digit_impl : integral_constant<unsigned, _Val>
65 static_assert(_Base > _Val,
"invalid digit");
69 template<
unsigned _Base>
70 struct _Digit<_Base, '2'> : _Digit_impl<_Base, 2>
73 template<
unsigned _Base>
74 struct _Digit<_Base, '3'> : _Digit_impl<_Base, 3>
77 template<
unsigned _Base>
78 struct _Digit<_Base, '4'> : _Digit_impl<_Base, 4>
81 template<
unsigned _Base>
82 struct _Digit<_Base, '5'> : _Digit_impl<_Base, 5>
85 template<
unsigned _Base>
86 struct _Digit<_Base, '6'> : _Digit_impl<_Base, 6>
89 template<
unsigned _Base>
90 struct _Digit<_Base, '7'> : _Digit_impl<_Base, 7>
93 template<
unsigned _Base>
94 struct _Digit<_Base, '8'> : _Digit_impl<_Base, 8>
97 template<
unsigned _Base>
98 struct _Digit<_Base, '9'> : _Digit_impl<_Base, 9>
101 template<
unsigned _Base>
102 struct _Digit<_Base, 'a'> : _Digit_impl<_Base, 0xa>
105 template<
unsigned _Base>
106 struct _Digit<_Base, 'A'> : _Digit_impl<_Base, 0xa>
109 template<
unsigned _Base>
110 struct _Digit<_Base, 'b'> : _Digit_impl<_Base, 0xb>
113 template<
unsigned _Base>
114 struct _Digit<_Base, 'B'> : _Digit_impl<_Base, 0xb>
117 template<
unsigned _Base>
118 struct _Digit<_Base, 'c'> : _Digit_impl<_Base, 0xc>
121 template<
unsigned _Base>
122 struct _Digit<_Base, 'C'> : _Digit_impl<_Base, 0xc>
125 template<
unsigned _Base>
126 struct _Digit<_Base, 'd'> : _Digit_impl<_Base, 0xd>
129 template<
unsigned _Base>
130 struct _Digit<_Base, 'D'> : _Digit_impl<_Base, 0xd>
133 template<
unsigned _Base>
134 struct _Digit<_Base, 'e'> : _Digit_impl<_Base, 0xe>
137 template<
unsigned _Base>
138 struct _Digit<_Base, 'E'> : _Digit_impl<_Base, 0xe>
141 template<
unsigned _Base>
142 struct _Digit<_Base, 'f'> : _Digit_impl<_Base, 0xf>
145 template<
unsigned _Base>
146 struct _Digit<_Base, 'F'> : _Digit_impl<_Base, 0xf>
150 template<
unsigned _Base>
151 struct _Digit<_Base, '\''> : integral_constant<unsigned, 0>
158 template<
unsigned long long _Val>
159 using __ull_constant = integral_constant<unsigned long long, _Val>;
161 template<
unsigned _Base,
char _Dig,
char... _Digs>
164 using __next =
typename _Power_help<_Base, _Digs...>::type;
165 using __valid_digit =
typename _Digit<_Base, _Dig>::__valid;
167 = __ull_constant<__next::value * (__valid_digit{} ? _Base : 1ULL)>;
170 template<
unsigned _Base,
char _Dig>
171 struct _Power_help<_Base, _Dig>
173 using __valid_digit =
typename _Digit<_Base, _Dig>::__valid;
174 using type = __ull_constant<__valid_digit::value>;
177 template<
unsigned _Base,
char... _Digs>
178 struct _Power : _Power_help<_Base, _Digs...>::type
181 template<
unsigned _Base>
182 struct _Power<_Base> : __ull_constant<0>
187 template<
unsigned _Base,
unsigned long long _Pow,
char _Dig,
char... _Digs>
190 using __digit = _Digit<_Base, _Dig>;
191 using __valid_digit =
typename __digit::__valid;
192 using __next = _Number_help<_Base,
193 __valid_digit::value ? _Pow / _Base : _Pow,
195 using type = __ull_constant<_Pow * __digit::value + __next::type::value>;
196 static_assert((type::value / _Pow) == __digit::value,
197 "integer literal does not fit in unsigned long long");
201 template<
unsigned _Base,
unsigned long long _Pow,
char _Dig,
char..._Digs>
202 struct _Number_help<_Base, _Pow, '\'', _Dig, _Digs...>
203 : _Number_help<_Base, _Pow, _Dig, _Digs...>
207 template<
unsigned _Base,
char _Dig>
208 struct _Number_help<_Base, 1ULL, _Dig>
210 using type = __ull_constant<_Digit<_Base, _Dig>::value>;
213 template<
unsigned _Base,
char... _Digs>
215 : _Number_help<_Base, _Power<_Base, _Digs...>::value, _Digs...>::type
218 template<
unsigned _Base>
219 struct _Number<_Base>
225 template<
char... _Digs>
228 template<
char... _Digs>
229 struct _Parse_int<'0', 'b', _Digs...>
230 : _Number<2U, _Digs...>::type
233 template<
char... _Digs>
234 struct _Parse_int<'0', 'B', _Digs...>
235 : _Number<2U, _Digs...>::type
238 template<
char... _Digs>
239 struct _Parse_int<'0', 'x', _Digs...>
240 : _Number<16U, _Digs...>::type
243 template<
char... _Digs>
244 struct _Parse_int<'0', 'X', _Digs...>
245 : _Number<16U, _Digs...>::type
248 template<
char... _Digs>
249 struct _Parse_int<'0', _Digs...>
250 : _Number<8U, _Digs...>::type
253 template<
char... _Digs>
255 : _Number<10U, _Digs...>::type
261 namespace __select_int
263 template<
unsigned long long _Val,
typename... _Ints>
264 struct _Select_int_base;
266 template<
unsigned long long _Val,
typename _IntType,
typename... _Ints>
267 struct _Select_int_base<_Val, _IntType, _Ints...>
268 :
conditional_t<(_Val <= std::numeric_limits<_IntType>::max()),
269 integral_constant<_IntType, _Val>,
270 _Select_int_base<_Val, _Ints...>>
273 template<unsigned long long _Val>
274 struct _Select_int_base<_Val>
277 template<char... _Digs>
278 using _Select_int = typename _Select_int_base<
279 __parse_int::_Parse_int<_Digs...>::value,
289 _GLIBCXX_END_NAMESPACE_VERSION
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
ISO C++ entities toplevel namespace is std.
typename conditional< _Cond, _Iftrue, _Iffalse >::type conditional_t
Alias template for conditional.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.