aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorSecMeant <secmeant@gmail.com>2020-06-27 01:22:24 +0200
committerSecMeant <secmeant@gmail.com>2020-06-27 01:22:24 +0200
commit83092fc5c65a56ea322bdbf3ffb78339175b0b8f (patch)
treeb0abd7a52be91b7d1e1ef657a76734eb0e4b718f /README.md
parent8b2e3c7bc5e6f66363c6256f5f7eb57e366d5b16 (diff)
Storing digits in variable, thus removing magic constant from template param check
Diffstat (limited to 'README.md')
-rw-r--r--README.md4
1 files changed, 3 insertions, 1 deletions
diff --git a/README.md b/README.md
index f2c55e1..bf3d129 100644
--- a/README.md
+++ b/README.md
@@ -48,11 +48,13 @@ The integer/string conversion is done using a simple method I learned over the y
(*Note: The below examples of code are not up-to-date, though they still give a general idea of how `to_string` works.*)
```cpp
+constexpr char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
constexpr to_string_t() {
auto ptr = buf + sizeof(buf) / sizeof(buf[0]);
*--ptr = '\0';
for (auto n = N < 0 ? -N : N; n; n /= base)
- *--ptr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n % base];
+ *--ptr = digits[n % base];
if (N < 0)
*--ptr = '-';
}