diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-31 13:11:22 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-31 13:11:22 +0100 |
commit | dc5d223c24c52310f69f1df3c176ead91288f561 (patch) | |
tree | bb33739189da4a281878bca498a58a9135c65f2e /lib | |
parent | Basic support for queries with bound parameters (diff) | |
download | mygrate-dc5d223c24c52310f69f1df3c176ead91288f561.tar.bz2 mygrate-dc5d223c24c52310f69f1df3c176ead91288f561.tar.xz mygrate-dc5d223c24c52310f69f1df3c176ead91288f561.zip |
CTF fixed string null termination
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compileTimeFormatter.h | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/compileTimeFormatter.h b/lib/compileTimeFormatter.h index 6e8c813..17da62e 100644 --- a/lib/compileTimeFormatter.h +++ b/lib/compileTimeFormatter.h @@ -7,6 +7,7 @@ #include <iostream> #include <optional> #include <sstream> // IWYU pragma: export +#include <string_view> namespace AdHoc { // Template char utils @@ -236,21 +237,49 @@ namespace AdHoc { // New C++20 implementation namespace support { - template<typename CharT, std::size_t N> class basic_fixed_string : public std::array<CharT, N> { + template<typename CharT, std::size_t N> class basic_fixed_string { public: // cppcheck-suppress noExplicitConstructor constexpr basic_fixed_string(const CharT (&str)[N + 1]) { for (decltype(N) x = 0; x < N; x++) { - this->at(x) = str[x]; + arr.at(x) = str[x]; } + arr.at(N) = '\0'; } constexpr basic_fixed_string(const CharT * str, decltype(N) len) { for (decltype(N) x = 0; x < len; x++) { - this->at(x) = str[x]; + arr.at(x) = str[x]; } + arr.at(N) = '\0'; } + constexpr const char * + s() const + { + return arr.data(); + } + constexpr operator const char *() const + { + return s(); + } + constexpr std::string_view + v() const + { + return {arr.data(), arr.size() - 1}; + } + constexpr auto & + operator[](std::size_t n) const + { + return arr[n]; + } + constexpr auto + size() const + { + return arr.size() - 1; + } + + std::array<CharT, N + 1> arr; }; template<typename CharT, std::size_t N> |