From 1e0c019453e5e534732c57f33a2433fde387b0ba Mon Sep 17 00:00:00 2001 From: neargye Date: Thu, 14 Nov 2019 17:00:20 +0500 Subject: [PATCH] some speed-up static_string --- include/nameof.hpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/nameof.hpp b/include/nameof.hpp index 0e67571..ec31083 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -269,7 +269,12 @@ struct nameof_enum_supported template struct static_string { - constexpr static_string(std::string_view str) noexcept : static_string{str, std::make_index_sequence{}} {} + constexpr explicit static_string(std::string_view str) noexcept : chars{} { + assert(str.size() == N); + for (std::size_t i = 0; i < N; ++i) { + chars[i] = str[i]; + } + } constexpr const char* data() const noexcept { return chars.data(); } @@ -278,10 +283,7 @@ struct static_string { constexpr operator std::string_view() const noexcept { return {data(), size()}; } private: - template - constexpr static_string(std::string_view str, std::index_sequence) noexcept : chars{{str[I]..., '\0'}} {} - - const std::array chars; + std::array chars; }; template <>