aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclyne <clyne@bitgloo.com>2020-06-26 16:41:17 -0400
committerGitHub <noreply@github.com>2020-06-26 16:41:17 -0400
commit37b7cd171543152a7569bfa63b6786ec21198f40 (patch)
treebb91a4ab744a46e82fca9429af80c32b8a4b04c7
parent2be778931d2029c3ff121023e5c2c217f69e61d5 (diff)
Initialize buf for C++17 GCC; make to_string constexpr
https://www.reddit.com/r/cpp/comments/hgcaih/compiletime_integertostring_conversion_c17/fw3d2fm/
-rw-r--r--to_string.hpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/to_string.hpp b/to_string.hpp
index 116cdd8..15df021 100644
--- a/to_string.hpp
+++ b/to_string.hpp
@@ -25,12 +25,12 @@ struct to_string_t {
unsigned int len = N >= 0 ? 1 : 2;
for (auto n = N < 0 ? -N : N; n; len++, n /= base);
return len;
- }())];
+ }())] = {};
/**
* Constructs the object, filling `buf` with the string representation of N.
*/
- constexpr to_string_t() {
+ constexpr to_string_t() noexcept {
auto ptr = buf + sizeof(buf) / sizeof(buf[0]);
*--ptr = '\0';
for (auto n = N < 0 ? -N : N; n; n /= base)
@@ -58,6 +58,6 @@ struct to_string_t {
* Simplifies use of `to_string_t` from `to_string_t<N>()` to `to_string<N>`.
*/
template<auto N, unsigned int base = 10>
-to_string_t<N, base> to_string;
+constexpr to_string_t<N, base> to_string;
#endif // TCSULLIVAN_TO_STRING_HPP_