File tree 1 file changed +4
-4
lines changed
1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change 15
15
* @tparam N Number to convert
16
16
* @tparam base Desired base, can be from 2 to 36
17
17
*/
18
- template <auto N, unsigned int base, typename char_type,
18
+ template <auto N, int base, typename char_type,
19
19
std::enable_if_t <std::is_integral_v<decltype(N)>, int > = 0 ,
20
20
std::enable_if_t <(base > 1 && base < 37 ), int > = 0 >
21
21
class to_string_t {
22
22
// The lambda calculates what the string length of N will be, so that `buf`
23
23
// fits to the number perfectly.
24
24
char_type buf[([]() constexpr noexcept {
25
25
unsigned int len = N > 0 ? 1 : 2 ;
26
- for (auto n = N < 0 ? -N : N ; n; len++, n /= base);
26
+ for (auto n = N; n; len++, n /= base);
27
27
return len;
28
28
}())] = {};
29
29
@@ -35,8 +35,8 @@ class to_string_t {
35
35
auto ptr = end ();
36
36
*--ptr = ' \0 ' ;
37
37
if (N != 0 ) {
38
- for (auto n = N < 0 ? -N : N ; n; n /= base)
39
- *--ptr = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" [n % base];
38
+ for (auto n = N; n; n /= base)
39
+ *--ptr = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" [(N < 0 ? - 1 : 1 ) * ( n % base) ];
40
40
if (N < 0 )
41
41
*--ptr = ' -' ;
42
42
} else {
You can’t perform that action at this time.
0 commit comments