From 36a25d75b4ce251a19144cc29e34986d4f7614ac Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Sat, 30 Jul 2022 11:25:10 +0500 Subject: [PATCH] Reuse detail::string_literal in the chrono formatter Signed-off-by: Vladislav Shchapov --- include/fmt/chrono.h | 15 +++------------ include/fmt/format.h | 12 ++++++++++++ include/fmt/ranges.h | 10 ---------- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/include/fmt/chrono.h b/include/fmt/chrono.h index 4440a4df..aef8fcc1 100644 --- a/include/fmt/chrono.h +++ b/include/fmt/chrono.h @@ -2002,8 +2002,9 @@ template struct formatter, Char> : formatter { FMT_CONSTEXPR formatter() { - this->do_parse(default_specs, - default_specs + sizeof(default_specs) / sizeof(Char)); + basic_string_view default_specs = + detail::string_literal{}; + this->do_parse(default_specs.begin(), default_specs.end()); } template @@ -2011,18 +2012,8 @@ struct formatter, FormatContext& ctx) const -> decltype(ctx.out()) { return formatter::format(localtime(val), ctx); } - - // EDG frontend (Intel, NVHPC compilers) can't determine array length. - static constexpr const Char default_specs[5] = {'%', 'F', ' ', '%', 'T'}; }; -#if FMT_CPLUSPLUS < 201703L -template -constexpr const Char - formatter, - Char>::default_specs[]; -#endif - template struct formatter { private: enum class spec { diff --git a/include/fmt/format.h b/include/fmt/format.h index 1de7b45e..d77f0e8e 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -249,6 +249,18 @@ FMT_CONSTEXPR inline void abort_fuzzing_if(bool condition) { #endif } +template struct string_literal { + static constexpr CharT value[sizeof...(C)] = {C...}; + constexpr operator basic_string_view() const { + return {value, sizeof...(C)}; + } +}; + +#if FMT_CPLUSPLUS < 201703L +template +constexpr CharT string_literal::value[sizeof...(C)]; +#endif + template class formatbuf : public Streambuf { private: using char_type = typename Streambuf::char_type; diff --git a/include/fmt/ranges.h b/include/fmt/ranges.h index 076a78b8..9e36c9a2 100644 --- a/include/fmt/ranges.h +++ b/include/fmt/ranges.h @@ -309,16 +309,6 @@ OutputIt write_range_entry(OutputIt out, const Arg& v) { return write(out, v); } -template struct string_literal { - static constexpr CharT value[sizeof...(C)] = {C...}; - constexpr operator basic_string_view() const { - return {value, sizeof...(C)}; - } -}; - -template -constexpr CharT string_literal::value[sizeof...(C)]; - } // namespace detail template struct is_tuple_like {