]> code.bitgloo.com Git - clyne/constexpr-to-string.git/commitdiff
Use end() in constructor
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 27 Jun 2020 22:31:53 +0000 (18:31 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 27 Jun 2020 22:31:53 +0000 (18:31 -0400)
to_string.hpp

index b9e0ccefd5e4ae399bfd59c5dede2180d5234e21..11e590674ee5fdccd72e9b93cf1f7a6d73e18106 100644 (file)
@@ -32,9 +32,9 @@ class to_string_t {
      * Constructs the object, filling `buf` with the string representation of N.
      */
     constexpr to_string_t() noexcept {
+        auto ptr = end();
+        *--ptr = '\0';
         if (N != 0) {
-            auto ptr = buf + sizeof(buf) / sizeof(buf[0]);
-            *--ptr = '\0';
             for (auto n = N < 0 ? -N : N; n; n /= base)
                 *--ptr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n % base];
             if (N < 0)