1 // Copyright (C) 2017 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++17" }
19 // { dg-do run { target c++17 } }
20 // { dg-require-string-conversions "" }
23 #include <string_view>
27 check_to_chars(I val
, std::string_view expected
, int base
= 0)
29 // Space for minus sign, 64 binary digits, final '*', and null terminator:
30 char buf
[67] = "******************************************************************";
31 std::to_chars_result r
= base
== 0
32 ? std::to_chars(buf
, buf
+sizeof(buf
), val
)
33 : std::to_chars(buf
, buf
+sizeof(buf
), val
, base
);
34 return r
.ec
== std::errc
{} && *r
.ptr
== '*' && std::string_view(buf
, r
.ptr
- buf
) == expected
;
39 #include <testsuite_hooks.h>
41 // Using default base 10
45 VERIFY( check_to_chars
<char>(0, "0") );
46 VERIFY( check_to_chars
<signed char>(0, "0") );
47 VERIFY( check_to_chars
<unsigned char>(0, "0") );
48 VERIFY( check_to_chars
<signed short>(0, "0") );
49 VERIFY( check_to_chars
<unsigned short>(0, "0") );
50 VERIFY( check_to_chars
<signed int>(0, "0") );
51 VERIFY( check_to_chars
<unsigned int>(0, "0") );
52 VERIFY( check_to_chars
<signed long>(0, "0") );
53 VERIFY( check_to_chars
<unsigned long>(0, "0") );
54 VERIFY( check_to_chars
<signed long long>(0, "0") );
55 VERIFY( check_to_chars
<unsigned long long>(0, "0") );
57 VERIFY( check_to_chars
<char>(1, "1") );
58 VERIFY( check_to_chars
<signed char>(1, "1") );
59 VERIFY( check_to_chars
<unsigned char>(1, "1") );
60 VERIFY( check_to_chars
<signed short>(1, "1") );
61 VERIFY( check_to_chars
<unsigned short>(1, "1") );
62 VERIFY( check_to_chars
<signed int>(1, "1") );
63 VERIFY( check_to_chars
<unsigned int>(1, "1") );
64 VERIFY( check_to_chars
<signed long>(1, "1") );
65 VERIFY( check_to_chars
<unsigned long>(1, "1") );
66 VERIFY( check_to_chars
<signed long long>(1, "1") );
67 VERIFY( check_to_chars
<unsigned long long>(1, "1") );
69 VERIFY( check_to_chars
<char>(123, "123") );
70 VERIFY( check_to_chars
<signed char>(123, "123") );
71 VERIFY( check_to_chars
<unsigned char>(123, "123") );
72 VERIFY( check_to_chars
<signed short>(123, "123") );
73 VERIFY( check_to_chars
<unsigned short>(123, "123") );
74 VERIFY( check_to_chars
<signed int>(123, "123") );
75 VERIFY( check_to_chars
<unsigned int>(123, "123") );
76 VERIFY( check_to_chars
<signed long>(123, "123") );
77 VERIFY( check_to_chars
<unsigned long>(123, "123") );
78 VERIFY( check_to_chars
<signed long long>(123, "123") );
79 VERIFY( check_to_chars
<unsigned long long>(123, "123") );
81 if constexpr (std::is_signed_v
<char>)
82 VERIFY( check_to_chars
<char>(-79, "-79") );
83 VERIFY( check_to_chars
<signed char>(-79, "-79") );
84 VERIFY( check_to_chars
<signed short>(-79, "-79") );
85 VERIFY( check_to_chars
<signed int>(-79, "-79") );
86 VERIFY( check_to_chars
<signed long>(-79, "-79") );
87 VERIFY( check_to_chars
<signed long long>(-79, "-79") );
91 VERIFY( check_to_chars
<char>(CHAR_MAX
, to_string(CHAR_MAX
)) );
92 VERIFY( check_to_chars
<signed char>(SCHAR_MAX
, to_string(SCHAR_MAX
)) );
93 VERIFY( check_to_chars
<unsigned char>(UCHAR_MAX
, to_string(UCHAR_MAX
)) );
94 VERIFY( check_to_chars
<signed short>(SHRT_MAX
, to_string(SHRT_MAX
)) );
95 VERIFY( check_to_chars
<unsigned short>(USHRT_MAX
, to_string(USHRT_MAX
)) );
96 VERIFY( check_to_chars
<signed int>(INT_MAX
, to_string(INT_MAX
)) );
97 VERIFY( check_to_chars
<unsigned int>(UINT_MAX
, to_string(UINT_MAX
)) );
98 VERIFY( check_to_chars
<signed long>(LONG_MAX
, to_string(LONG_MAX
)) );
99 VERIFY( check_to_chars
<unsigned long>(ULONG_MAX
, to_string(ULONG_MAX
)) );
100 VERIFY( check_to_chars
<signed long long>(LLONG_MAX
, to_string(LLONG_MAX
)) );
101 VERIFY( check_to_chars
<unsigned long long>(ULLONG_MAX
, to_string(ULLONG_MAX
)) );
103 VERIFY( check_to_chars
<char>(CHAR_MIN
, to_string(CHAR_MIN
)) );
104 VERIFY( check_to_chars
<signed char>(SCHAR_MIN
, to_string(SCHAR_MIN
)) );
105 VERIFY( check_to_chars
<signed short>(SHRT_MIN
, to_string(SHRT_MIN
)) );
106 VERIFY( check_to_chars
<signed int>(INT_MIN
, to_string(INT_MIN
)) );
107 VERIFY( check_to_chars
<signed long>(LONG_MIN
, to_string(LONG_MIN
)) );
108 VERIFY( check_to_chars
<signed long long>(LLONG_MIN
, to_string(LLONG_MIN
)) );
110 VERIFY( check_to_chars
<char>(CHAR_MAX
/2, to_string(CHAR_MAX
/2)) );
111 VERIFY( check_to_chars
<signed char>(SCHAR_MAX
/2, to_string(SCHAR_MAX
/2)) );
112 VERIFY( check_to_chars
<unsigned char>(UCHAR_MAX
/2, to_string(UCHAR_MAX
/2)) );
113 VERIFY( check_to_chars
<signed short>(SHRT_MAX
/2, to_string(SHRT_MAX
/2)) );
114 VERIFY( check_to_chars
<unsigned short>(USHRT_MAX
/2, to_string(USHRT_MAX
/2)) );
115 VERIFY( check_to_chars
<signed int>(INT_MAX
/2, to_string(INT_MAX
/2)) );
116 VERIFY( check_to_chars
<unsigned int>(UINT_MAX
/2, to_string(UINT_MAX
/2)) );
117 VERIFY( check_to_chars
<signed long>(LONG_MAX
/2, to_string(LONG_MAX
/2)) );
118 VERIFY( check_to_chars
<unsigned long>(ULONG_MAX
/2, to_string(ULONG_MAX
/2)) );
119 VERIFY( check_to_chars
<signed long long>(LLONG_MAX
/2, to_string(LLONG_MAX
/2)) );
120 VERIFY( check_to_chars
<unsigned long long>(ULLONG_MAX
/2, to_string(ULLONG_MAX
/2)) );
123 // Using explicit base 10
127 VERIFY( check_to_chars
<char>(0, "0", 10) );
128 VERIFY( check_to_chars
<signed char>(0, "0", 10) );
129 VERIFY( check_to_chars
<unsigned char>(0, "0", 10) );
130 VERIFY( check_to_chars
<signed short>(0, "0", 10) );
131 VERIFY( check_to_chars
<unsigned short>(0, "0", 10) );
132 VERIFY( check_to_chars
<signed int>(0, "0", 10) );
133 VERIFY( check_to_chars
<unsigned int>(0, "0", 10) );
134 VERIFY( check_to_chars
<signed long>(0, "0", 10) );
135 VERIFY( check_to_chars
<unsigned long>(0, "0", 10) );
136 VERIFY( check_to_chars
<signed long long>(0, "0", 10) );
137 VERIFY( check_to_chars
<unsigned long long>(0, "0", 10) );
139 VERIFY( check_to_chars
<char>(1, "1", 10) );
140 VERIFY( check_to_chars
<signed char>(1, "1", 10) );
141 VERIFY( check_to_chars
<unsigned char>(1, "1", 10) );
142 VERIFY( check_to_chars
<signed short>(1, "1", 10) );
143 VERIFY( check_to_chars
<unsigned short>(1, "1", 10) );
144 VERIFY( check_to_chars
<signed int>(1, "1", 10) );
145 VERIFY( check_to_chars
<unsigned int>(1, "1", 10) );
146 VERIFY( check_to_chars
<signed long>(1, "1", 10) );
147 VERIFY( check_to_chars
<unsigned long>(1, "1", 10) );
148 VERIFY( check_to_chars
<signed long long>(1, "1", 10) );
149 VERIFY( check_to_chars
<unsigned long long>(1, "1", 10) );
151 VERIFY( check_to_chars
<char>(123, "123", 10) );
152 VERIFY( check_to_chars
<signed char>(123, "123", 10) );
153 VERIFY( check_to_chars
<unsigned char>(123, "123", 10) );
154 VERIFY( check_to_chars
<signed short>(123, "123", 10) );
155 VERIFY( check_to_chars
<unsigned short>(123, "123", 10) );
156 VERIFY( check_to_chars
<signed int>(123, "123", 10) );
157 VERIFY( check_to_chars
<unsigned int>(123, "123", 10) );
158 VERIFY( check_to_chars
<signed long>(123, "123", 10) );
159 VERIFY( check_to_chars
<unsigned long>(123, "123", 10) );
160 VERIFY( check_to_chars
<signed long long>(123, "123", 10) );
161 VERIFY( check_to_chars
<unsigned long long>(123, "123", 10) );
163 if constexpr (std::is_signed_v
<char>)
164 VERIFY( check_to_chars
<char>(-79, "-79", 10) );
165 VERIFY( check_to_chars
<signed char>(-79, "-79", 10) );
166 VERIFY( check_to_chars
<signed short>(-79, "-79", 10) );
167 VERIFY( check_to_chars
<signed int>(-79, "-79", 10) );
168 VERIFY( check_to_chars
<signed long>(-79, "-79", 10) );
169 VERIFY( check_to_chars
<signed long long>(-79, "-79", 10) );
171 using std::to_string
;
173 VERIFY( check_to_chars
<char>(CHAR_MAX
, to_string(CHAR_MAX
), 10) );
174 VERIFY( check_to_chars
<signed char>(SCHAR_MAX
, to_string(SCHAR_MAX
), 10) );
175 VERIFY( check_to_chars
<unsigned char>(UCHAR_MAX
, to_string(UCHAR_MAX
), 10) );
176 VERIFY( check_to_chars
<signed short>(SHRT_MAX
, to_string(SHRT_MAX
), 10) );
177 VERIFY( check_to_chars
<unsigned short>(USHRT_MAX
, to_string(USHRT_MAX
), 10) );
178 VERIFY( check_to_chars
<signed int>(INT_MAX
, to_string(INT_MAX
), 10) );
179 VERIFY( check_to_chars
<unsigned int>(UINT_MAX
, to_string(UINT_MAX
), 10) );
180 VERIFY( check_to_chars
<signed long>(LONG_MAX
, to_string(LONG_MAX
), 10) );
181 VERIFY( check_to_chars
<unsigned long>(ULONG_MAX
, to_string(ULONG_MAX
), 10) );
182 VERIFY( check_to_chars
<signed long long>(LLONG_MAX
, to_string(LLONG_MAX
), 10) );
183 VERIFY( check_to_chars
<unsigned long long>(ULLONG_MAX
, to_string(ULLONG_MAX
), 10) );
185 VERIFY( check_to_chars
<char>(CHAR_MIN
, to_string(CHAR_MIN
), 10) );
186 VERIFY( check_to_chars
<signed char>(SCHAR_MIN
, to_string(SCHAR_MIN
), 10) );
187 VERIFY( check_to_chars
<signed short>(SHRT_MIN
, to_string(SHRT_MIN
), 10) );
188 VERIFY( check_to_chars
<signed int>(INT_MIN
, to_string(INT_MIN
), 10) );
189 VERIFY( check_to_chars
<signed long>(LONG_MIN
, to_string(LONG_MIN
), 10) );
190 VERIFY( check_to_chars
<signed long long>(LLONG_MIN
, to_string(LLONG_MIN
), 10) );
192 VERIFY( check_to_chars
<char>(CHAR_MAX
/2, to_string(CHAR_MAX
/2), 10) );
193 VERIFY( check_to_chars
<signed char>(SCHAR_MAX
/2, to_string(SCHAR_MAX
/2), 10) );
194 VERIFY( check_to_chars
<unsigned char>(UCHAR_MAX
/2, to_string(UCHAR_MAX
/2), 10) );
195 VERIFY( check_to_chars
<signed short>(SHRT_MAX
/2, to_string(SHRT_MAX
/2), 10) );
196 VERIFY( check_to_chars
<unsigned short>(USHRT_MAX
/2, to_string(USHRT_MAX
/2), 10) );
197 VERIFY( check_to_chars
<signed int>(INT_MAX
/2, to_string(INT_MAX
/2), 10) );
198 VERIFY( check_to_chars
<unsigned int>(UINT_MAX
/2, to_string(UINT_MAX
/2), 10) );
199 VERIFY( check_to_chars
<signed long>(LONG_MAX
/2, to_string(LONG_MAX
/2), 10) );
200 VERIFY( check_to_chars
<unsigned long>(ULONG_MAX
/2, to_string(ULONG_MAX
/2), 10) );
201 VERIFY( check_to_chars
<signed long long>(LLONG_MAX
/2, to_string(LLONG_MAX
/2), 10) );
202 VERIFY( check_to_chars
<unsigned long long>(ULLONG_MAX
/2, to_string(ULLONG_MAX
/2), 10) );
209 // -2017 in all bases from [2,36]
210 const char* str2017
[37] = { nullptr, nullptr,
247 // -12345 in all bases from [2,36]
248 const char* str12345
[37] = { nullptr, nullptr,
285 // -23456 in all bases from [2,36]
286 const char* str23456
[37] = { nullptr, nullptr,
323 // INT_MIN in all bases from [2,36]
324 const char* strINT_MIN
[37] = { nullptr, nullptr,
325 "-10000000000000000000000000000000",
326 "-12112122212110202102",
362 for (int base
= 2; base
<= 36; ++base
)
364 VERIFY( check_to_chars
<char>(0, "0", base
) );
365 VERIFY( check_to_chars
<signed char>(0, "0", base
) );
366 VERIFY( check_to_chars
<unsigned char>(0, "0", base
) );
367 VERIFY( check_to_chars
<signed short>(0, "0", base
) );
368 VERIFY( check_to_chars
<unsigned short>(0, "0", base
) );
369 VERIFY( check_to_chars
<signed int>(0, "0", base
) );
370 VERIFY( check_to_chars
<unsigned int>(0, "0", base
) );
371 VERIFY( check_to_chars
<signed long>(0, "0", base
) );
372 VERIFY( check_to_chars
<unsigned long>(0, "0", base
) );
373 VERIFY( check_to_chars
<signed long long>(0, "0", base
) );
374 VERIFY( check_to_chars
<unsigned long long>(0, "0", base
) );
376 VERIFY( check_to_chars
<char>(1, "1", base
) );
377 VERIFY( check_to_chars
<signed char>(1, "1", base
) );
378 VERIFY( check_to_chars
<unsigned char>(1, "1", base
) );
379 VERIFY( check_to_chars
<signed short>(1, "1", base
) );
380 VERIFY( check_to_chars
<unsigned short>(1, "1", base
) );
381 VERIFY( check_to_chars
<signed int>(1, "1", base
) );
382 VERIFY( check_to_chars
<unsigned int>(1, "1", base
) );
383 VERIFY( check_to_chars
<signed long>(1, "1", base
) );
384 VERIFY( check_to_chars
<unsigned long>(1, "1", base
) );
385 VERIFY( check_to_chars
<signed long long>(1, "1", base
) );
386 VERIFY( check_to_chars
<unsigned long long>(1, "1", base
) );
388 if constexpr (std::is_signed_v
<char>)
389 VERIFY( check_to_chars
<char>(-1, "-1", base
) );
390 VERIFY( check_to_chars
<signed char>(-1, "-1", base
) );
391 VERIFY( check_to_chars
<signed short>(-1, "-1", base
) );
392 VERIFY( check_to_chars
<signed int>(-1, "-1", base
) );
393 VERIFY( check_to_chars
<signed long>(-1, "-1", base
) );
394 VERIFY( check_to_chars
<signed long long>(-1, "-1", base
) );
398 VERIFY( check_to_chars
<char>(2, "2", base
) );
399 VERIFY( check_to_chars
<signed char>(2, "2", base
) );
400 VERIFY( check_to_chars
<unsigned char>(2, "2", base
) );
401 VERIFY( check_to_chars
<signed short>(2, "2", base
) );
402 VERIFY( check_to_chars
<unsigned short>(2, "2", base
) );
403 VERIFY( check_to_chars
<signed int>(2, "2", base
) );
404 VERIFY( check_to_chars
<unsigned int>(2, "2", base
) );
405 VERIFY( check_to_chars
<signed long>(2, "2", base
) );
406 VERIFY( check_to_chars
<unsigned long>(2, "2", base
) );
407 VERIFY( check_to_chars
<signed long long>(2, "2", base
) );
408 VERIFY( check_to_chars
<unsigned long long>(2, "2", base
) );
410 if constexpr (std::is_signed_v
<char>)
411 VERIFY( check_to_chars
<char>(-2, "-2", base
) );
412 VERIFY( check_to_chars
<signed char>(-2, "-2", base
) );
413 VERIFY( check_to_chars
<signed short>(-2, "-2", base
) );
414 VERIFY( check_to_chars
<signed int>(-2, "-2", base
) );
415 VERIFY( check_to_chars
<signed long>(-2, "-2", base
) );
416 VERIFY( check_to_chars
<signed long long>(-2, "-2", base
) );
419 VERIFY( check_to_chars(2017u, str2017
[base
]+1, base
) );
420 VERIFY( check_to_chars(2017, str2017
[base
]+1, base
) );
421 VERIFY( check_to_chars(-2017, str2017
[base
], base
) );
422 VERIFY( check_to_chars(12345u, str12345
[base
]+1, base
) );
423 VERIFY( check_to_chars(12345, str12345
[base
]+1, base
) );
424 VERIFY( check_to_chars(-12345, str12345
[base
], base
) );
425 VERIFY( check_to_chars(23456u, str23456
[base
]+1, base
) );
426 VERIFY( check_to_chars(23456, str23456
[base
]+1, base
) );
427 VERIFY( check_to_chars(-23456, str23456
[base
], base
) );
428 VERIFY( check_to_chars(INT_MAX
+ 1ull, strINT_MIN
[base
]+1, base
) );
429 VERIFY( check_to_chars(INT_MAX
+ 1ll, strINT_MIN
[base
]+1, base
) );
430 VERIFY( check_to_chars(INT_MIN
, strINT_MIN
[base
], base
) );
433 VERIFY( check_to_chars(1155, "xx", 34) );
434 VERIFY( check_to_chars(1224, "yy", 35) );
435 VERIFY( check_to_chars(1295, "zz", 36) );
445 auto to_string
= [](auto val
) {
446 std::ostringstream ss
;
449 ss
<< '-' << (~val
+ 1ull);
450 else if (sizeof(val
) == 1)
457 VERIFY( check_to_chars
<char>(123, to_string(123), 8) );
458 VERIFY( check_to_chars
<signed char>(123, to_string(123), 8) );
459 VERIFY( check_to_chars
<unsigned char>(123, to_string(123), 8) );
460 VERIFY( check_to_chars
<signed short>(123, to_string(123), 8) );
461 VERIFY( check_to_chars
<unsigned short>(123, to_string(123), 8) );
462 VERIFY( check_to_chars
<signed int>(123, to_string(123), 8) );
463 VERIFY( check_to_chars
<unsigned int>(123, to_string(123), 8) );
464 VERIFY( check_to_chars
<signed long>(123, to_string(123), 8) );
465 VERIFY( check_to_chars
<unsigned long>(123, to_string(123), 8) );
466 VERIFY( check_to_chars
<signed long long>(123, to_string(123), 8) );
467 VERIFY( check_to_chars
<unsigned long long>(123, to_string(123), 8) );
469 if constexpr (std::is_signed_v
<char>)
470 VERIFY( check_to_chars
<char>(-79, to_string(-79), 8) );
471 VERIFY( check_to_chars
<signed char>(-79, to_string(-79), 8) );
472 VERIFY( check_to_chars
<signed short>(-79, to_string(-79), 8) );
473 VERIFY( check_to_chars
<signed int>(-79, to_string(-79), 8) );
474 VERIFY( check_to_chars
<signed long>(-79, to_string(-79), 8) );
475 VERIFY( check_to_chars
<signed long long>(-79, to_string(-79), 8) );
477 VERIFY( check_to_chars
<char>(CHAR_MAX
, to_string(CHAR_MAX
), 8) );
478 VERIFY( check_to_chars
<signed char>(SCHAR_MAX
, to_string(SCHAR_MAX
), 8) );
479 VERIFY( check_to_chars
<unsigned char>(UCHAR_MAX
, to_string(UCHAR_MAX
), 8) );
480 VERIFY( check_to_chars
<signed short>(SHRT_MAX
, to_string(SHRT_MAX
), 8) );
481 VERIFY( check_to_chars
<unsigned short>(USHRT_MAX
, to_string(USHRT_MAX
), 8) );
482 VERIFY( check_to_chars
<signed int>(INT_MAX
, to_string(INT_MAX
), 8) );
483 VERIFY( check_to_chars
<unsigned int>(UINT_MAX
, to_string(UINT_MAX
), 8) );
484 VERIFY( check_to_chars
<signed long>(LONG_MAX
, to_string(LONG_MAX
), 8) );
485 VERIFY( check_to_chars
<unsigned long>(ULONG_MAX
, to_string(ULONG_MAX
), 8) );
486 VERIFY( check_to_chars
<signed long long>(LLONG_MAX
, to_string(LLONG_MAX
), 8) );
487 VERIFY( check_to_chars
<unsigned long long>(ULLONG_MAX
, to_string(ULLONG_MAX
), 8) );
489 VERIFY( check_to_chars
<char>(CHAR_MIN
, to_string(CHAR_MIN
), 8) );
490 VERIFY( check_to_chars
<signed char>(SCHAR_MIN
, to_string(SCHAR_MIN
), 8) );
491 VERIFY( check_to_chars
<signed short>(SHRT_MIN
, to_string(SHRT_MIN
), 8) );
492 VERIFY( check_to_chars
<signed int>(INT_MIN
, to_string(INT_MIN
), 8) );
493 VERIFY( check_to_chars
<signed long>(LONG_MIN
, to_string(LONG_MIN
), 8) );
494 VERIFY( check_to_chars
<signed long long>(LLONG_MIN
, to_string(LLONG_MIN
), 8) );
496 VERIFY( check_to_chars
<char>(CHAR_MAX
/2, to_string(CHAR_MAX
/2), 8) );
497 VERIFY( check_to_chars
<signed char>(SCHAR_MAX
/2, to_string(SCHAR_MAX
/2), 8) );
498 VERIFY( check_to_chars
<unsigned char>(UCHAR_MAX
/2, to_string(UCHAR_MAX
/2), 8) );
499 VERIFY( check_to_chars
<signed short>(SHRT_MAX
/2, to_string(SHRT_MAX
/2), 8) );
500 VERIFY( check_to_chars
<unsigned short>(USHRT_MAX
/2, to_string(USHRT_MAX
/2), 8) );
501 VERIFY( check_to_chars
<signed int>(INT_MAX
/2, to_string(INT_MAX
/2), 8) );
502 VERIFY( check_to_chars
<unsigned int>(UINT_MAX
/2, to_string(UINT_MAX
/2), 8) );
503 VERIFY( check_to_chars
<signed long>(LONG_MAX
/2, to_string(LONG_MAX
/2), 8) );
504 VERIFY( check_to_chars
<unsigned long>(ULONG_MAX
/2, to_string(ULONG_MAX
/2), 8) );
505 VERIFY( check_to_chars
<signed long long>(LLONG_MAX
/2, to_string(LLONG_MAX
/2), 8) );
506 VERIFY( check_to_chars
<unsigned long long>(ULLONG_MAX
/2, to_string(ULLONG_MAX
/2), 8) );
513 auto to_string
= [](auto val
) {
514 std::ostringstream ss
;
517 ss
<< '-' << (~val
+ 1ull);
518 else if (sizeof(val
) == 1)
525 VERIFY( check_to_chars
<char>(123, to_string(123), 16) );
526 VERIFY( check_to_chars
<signed char>(123, to_string(123), 16) );
527 VERIFY( check_to_chars
<unsigned char>(123, to_string(123), 16) );
528 VERIFY( check_to_chars
<signed short>(123, to_string(123), 16) );
529 VERIFY( check_to_chars
<unsigned short>(123, to_string(123), 16) );
530 VERIFY( check_to_chars
<signed int>(123, to_string(123), 16) );
531 VERIFY( check_to_chars
<unsigned int>(123, to_string(123), 16) );
532 VERIFY( check_to_chars
<signed long>(123, to_string(123), 16) );
533 VERIFY( check_to_chars
<unsigned long>(123, to_string(123), 16) );
534 VERIFY( check_to_chars
<signed long long>(123, to_string(123), 16) );
535 VERIFY( check_to_chars
<unsigned long long>(123, to_string(123), 16) );
537 if constexpr (std::is_signed_v
<char>)
538 VERIFY( check_to_chars
<char>(-79, to_string(-79), 16) );
539 VERIFY( check_to_chars
<signed char>(-79, to_string(-79), 16) );
540 VERIFY( check_to_chars
<signed short>(-79, to_string(-79), 16) );
541 VERIFY( check_to_chars
<signed int>(-79, to_string(-79), 16) );
542 VERIFY( check_to_chars
<signed long>(-79, to_string(-79), 16) );
543 VERIFY( check_to_chars
<signed long long>(-79, to_string(-79), 16) );
545 VERIFY( check_to_chars
<char>(CHAR_MAX
, to_string(CHAR_MAX
), 16) );
546 VERIFY( check_to_chars
<signed char>(SCHAR_MAX
, to_string(SCHAR_MAX
), 16) );
547 VERIFY( check_to_chars
<unsigned char>(UCHAR_MAX
, to_string(UCHAR_MAX
), 16) );
548 VERIFY( check_to_chars
<signed short>(SHRT_MAX
, to_string(SHRT_MAX
), 16) );
549 VERIFY( check_to_chars
<unsigned short>(USHRT_MAX
, to_string(USHRT_MAX
), 16) );
550 VERIFY( check_to_chars
<signed int>(INT_MAX
, to_string(INT_MAX
), 16) );
551 VERIFY( check_to_chars
<unsigned int>(UINT_MAX
, to_string(UINT_MAX
), 16) );
552 VERIFY( check_to_chars
<signed long>(LONG_MAX
, to_string(LONG_MAX
), 16) );
553 VERIFY( check_to_chars
<unsigned long>(ULONG_MAX
, to_string(ULONG_MAX
), 16) );
554 VERIFY( check_to_chars
<signed long long>(LLONG_MAX
, to_string(LLONG_MAX
), 16) );
555 VERIFY( check_to_chars
<unsigned long long>(ULLONG_MAX
, to_string(ULLONG_MAX
), 16) );
557 VERIFY( check_to_chars
<char>(CHAR_MIN
, to_string(CHAR_MIN
), 16) );
558 VERIFY( check_to_chars
<signed char>(SCHAR_MIN
, to_string(SCHAR_MIN
), 16) );
559 VERIFY( check_to_chars
<signed short>(SHRT_MIN
, to_string(SHRT_MIN
), 16) );
560 VERIFY( check_to_chars
<signed int>(INT_MIN
, to_string(INT_MIN
), 16) );
561 VERIFY( check_to_chars
<signed long>(LONG_MIN
, to_string(LONG_MIN
), 16) );
562 VERIFY( check_to_chars
<signed long long>(LLONG_MIN
, to_string(LLONG_MIN
), 16) );
564 VERIFY( check_to_chars
<char>(CHAR_MAX
/2, to_string(CHAR_MAX
/2), 16) );
565 VERIFY( check_to_chars
<signed char>(SCHAR_MAX
/2, to_string(SCHAR_MAX
/2), 16) );
566 VERIFY( check_to_chars
<unsigned char>(UCHAR_MAX
/2, to_string(UCHAR_MAX
/2), 16) );
567 VERIFY( check_to_chars
<signed short>(SHRT_MAX
/2, to_string(SHRT_MAX
/2), 16) );
568 VERIFY( check_to_chars
<unsigned short>(USHRT_MAX
/2, to_string(USHRT_MAX
/2), 16) );
569 VERIFY( check_to_chars
<signed int>(INT_MAX
/2, to_string(INT_MAX
/2), 16) );
570 VERIFY( check_to_chars
<unsigned int>(UINT_MAX
/2, to_string(UINT_MAX
/2), 16) );
571 VERIFY( check_to_chars
<signed long>(LONG_MAX
/2, to_string(LONG_MAX
/2), 16) );
572 VERIFY( check_to_chars
<unsigned long>(ULONG_MAX
/2, to_string(ULONG_MAX
/2), 16) );
573 VERIFY( check_to_chars
<signed long long>(LLONG_MAX
/2, to_string(LLONG_MAX
/2), 16) );
574 VERIFY( check_to_chars
<unsigned long long>(ULLONG_MAX
/2, to_string(ULLONG_MAX
/2), 16) );
583 auto to_string
= [](auto val
) {
587 auto absval
= ~val
+ 1ull;
588 s
= std::bitset
<sizeof(absval
) * CHAR_BIT
>(absval
).to_string();
592 s
= std::bitset
<sizeof(val
) * CHAR_BIT
>(val
).to_string();
593 auto pos
= s
.find_first_not_of("0");
594 if (pos
== std::string::npos
)
601 VERIFY( check_to_chars
<char>(123, to_string(123), 2) );
602 VERIFY( check_to_chars
<signed char>(123, to_string(123), 2) );
603 VERIFY( check_to_chars
<unsigned char>(123, to_string(123), 2) );
604 VERIFY( check_to_chars
<signed short>(123, to_string(123), 2) );
605 VERIFY( check_to_chars
<unsigned short>(123, to_string(123), 2) );
606 VERIFY( check_to_chars
<signed int>(123, to_string(123), 2) );
607 VERIFY( check_to_chars
<unsigned int>(123, to_string(123), 2) );
608 VERIFY( check_to_chars
<signed long>(123, to_string(123), 2) );
609 VERIFY( check_to_chars
<unsigned long>(123, to_string(123), 2) );
610 VERIFY( check_to_chars
<signed long long>(123, to_string(123), 2) );
611 VERIFY( check_to_chars
<unsigned long long>(123, to_string(123), 2) );
613 if constexpr (std::is_signed_v
<char>)
614 VERIFY( check_to_chars
<char>(-79, to_string(-79), 2) );
615 VERIFY( check_to_chars
<signed char>(-79, to_string(-79), 2) );
616 VERIFY( check_to_chars
<signed short>(-79, to_string(-79), 2) );
617 VERIFY( check_to_chars
<signed int>(-79, to_string(-79), 2) );
618 VERIFY( check_to_chars
<signed long>(-79, to_string(-79), 2) );
619 VERIFY( check_to_chars
<signed long long>(-79, to_string(-79), 2) );
621 VERIFY( check_to_chars
<char>(CHAR_MAX
, to_string(CHAR_MAX
), 2) );
622 VERIFY( check_to_chars
<signed char>(SCHAR_MAX
, to_string(SCHAR_MAX
), 2) );
623 VERIFY( check_to_chars
<unsigned char>(UCHAR_MAX
, to_string(UCHAR_MAX
), 2) );
624 VERIFY( check_to_chars
<signed short>(SHRT_MAX
, to_string(SHRT_MAX
), 2) );
625 VERIFY( check_to_chars
<unsigned short>(USHRT_MAX
, to_string(USHRT_MAX
), 2) );
626 VERIFY( check_to_chars
<signed int>(INT_MAX
, to_string(INT_MAX
), 2) );
627 VERIFY( check_to_chars
<unsigned int>(UINT_MAX
, to_string(UINT_MAX
), 2) );
628 VERIFY( check_to_chars
<signed long>(LONG_MAX
, to_string(LONG_MAX
), 2) );
629 VERIFY( check_to_chars
<unsigned long>(ULONG_MAX
, to_string(ULONG_MAX
), 2) );
630 VERIFY( check_to_chars
<signed long long>(LLONG_MAX
, to_string(LLONG_MAX
), 2) );
631 VERIFY( check_to_chars
<unsigned long long>(ULLONG_MAX
, to_string(ULLONG_MAX
), 2) );
633 VERIFY( check_to_chars
<char>(CHAR_MIN
, to_string(CHAR_MIN
), 2) );
634 VERIFY( check_to_chars
<signed char>(SCHAR_MIN
, to_string(SCHAR_MIN
), 2) );
635 VERIFY( check_to_chars
<signed short>(SHRT_MIN
, to_string(SHRT_MIN
), 2) );
636 VERIFY( check_to_chars
<signed int>(INT_MIN
, to_string(INT_MIN
), 2) );
637 VERIFY( check_to_chars
<signed long>(LONG_MIN
, to_string(LONG_MIN
), 2) );
638 VERIFY( check_to_chars
<signed long long>(LLONG_MIN
, to_string(LLONG_MIN
), 2) );
640 VERIFY( check_to_chars
<char>(CHAR_MAX
/2, to_string(CHAR_MAX
/2), 2) );
641 VERIFY( check_to_chars
<signed char>(SCHAR_MAX
/2, to_string(SCHAR_MAX
/2), 2) );
642 VERIFY( check_to_chars
<unsigned char>(UCHAR_MAX
/2, to_string(UCHAR_MAX
/2), 2) );
643 VERIFY( check_to_chars
<signed short>(SHRT_MAX
/2, to_string(SHRT_MAX
/2), 2) );
644 VERIFY( check_to_chars
<unsigned short>(USHRT_MAX
/2, to_string(USHRT_MAX
/2), 2) );
645 VERIFY( check_to_chars
<signed int>(INT_MAX
/2, to_string(INT_MAX
/2), 2) );
646 VERIFY( check_to_chars
<unsigned int>(UINT_MAX
/2, to_string(UINT_MAX
/2), 2) );
647 VERIFY( check_to_chars
<signed long>(LONG_MAX
/2, to_string(LONG_MAX
/2), 2) );
648 VERIFY( check_to_chars
<unsigned long>(ULONG_MAX
/2, to_string(ULONG_MAX
/2), 2) );
649 VERIFY( check_to_chars
<signed long long>(LLONG_MAX
/2, to_string(LLONG_MAX
/2), 2) );
650 VERIFY( check_to_chars
<unsigned long long>(ULLONG_MAX
/2, to_string(ULLONG_MAX
/2), 2) );