some speed-up static_string

This commit is contained in:
neargye 2019-11-14 17:00:20 +05:00
parent 5e198e9983
commit 1e0c019453

View file

@ -269,7 +269,12 @@ struct nameof_enum_supported
template <std::size_t N> template <std::size_t N>
struct static_string { struct static_string {
constexpr static_string(std::string_view str) noexcept : static_string{str, std::make_index_sequence<N>{}} {} 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(); } 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()}; } constexpr operator std::string_view() const noexcept { return {data(), size()}; }
private: private:
template <std::size_t... I> std::array<char, N + 1> chars;
constexpr static_string(std::string_view str, std::index_sequence<I...>) noexcept : chars{{str[I]..., '\0'}} {}
const std::array<char, N + 1> chars;
}; };
template <> template <>