From 8dfd9e49ad94f1e1d95deb16fcd2a794c7a7c72f Mon Sep 17 00:00:00 2001 From: clyne Date: Fri, 26 Jun 2020 18:05:11 -0400 Subject: [PATCH] Add support for different character widths --- to_string.hpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/to_string.hpp b/to_string.hpp index 445c97f..21b5f48 100644 --- a/to_string.hpp +++ b/to_string.hpp @@ -15,17 +15,17 @@ * @tparam N Number to convert * @tparam base Desired base, can be from 2 to 36 */ -template, int> = 0, std::enable_if_t<(base > 1 && base < 37), int> = 0> struct to_string_t { // The lambda calculates what the string length of N will be, so that `buf` // fits to the number perfectly. - char buf[([] { - unsigned int len = N > 0 ? 1 : 2; - for (auto n = N < 0 ? -N : N; n; len++, n /= base); - return len; - }())] = {}; + char_type buf[([] { + 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. @@ -46,14 +46,14 @@ struct to_string_t { /** * Allows implicit conversion of this object to a `char *`. */ - constexpr operator char *() { + constexpr operator char_type *() { return buf; } /** * Allows implicit conversion of this object to a `const char *`. */ - constexpr operator const char *() const { + constexpr operator const char_type *() const { return buf; } }; @@ -61,7 +61,7 @@ struct to_string_t { /** * Simplifies use of `to_string_t` from `to_string_t()` to `to_string`. */ -template -constexpr to_string_t to_string; +template +constexpr to_string_t to_string; #endif // TCSULLIVAN_TO_STRING_HPP_