From 2c5d82a7c0762c242f2ef1bcd902a17c0fbd9515 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 28 Mar 2020 14:22:21 +0000 Subject: Simplify fmt literal with basic_fixed_string --- libadhocutil/compileTimeFormatter.h | 50 +++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h index 46b7ec9..d13492a 100644 --- a/libadhocutil/compileTimeFormatter.h +++ b/libadhocutil/compileTimeFormatter.h @@ -222,27 +222,6 @@ namespace AdHoc { }; }; - namespace literals { -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template" -#endif - /// CTF format string holder - template struct FMT - { - /// CTF format string - // NOLINTNEXTLINE(hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - static constexpr char __FMT[] = {t...}; - }; - template inline auto operator""_fmt() noexcept - { - return AdHoc::FormatterDetail::__FMT, sizeof...(t)>(); - } -#ifdef __clang__ -#pragma clang diagnostic pop -#endif - } - #ifdef USE_FIXED_STRING // New C++20 implementation namespace support { @@ -308,6 +287,35 @@ namespace AdHoc { AdHocFormatterTypedef(name, str, MAKE_UNIQUE(name)) #endif + + namespace literals { +#ifdef USE_FIXED_STRING + template + constexpr inline auto operator""_fmt() noexcept + { + return AdHoc::FormatterDetail(); + } +#else +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template" +#endif + /// CTF format string holder + template struct FMT + { + /// CTF format string + // NOLINTNEXTLINE(hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + static constexpr char __FMT[] = {t...}; + }; + template inline auto operator""_fmt() noexcept + { + return AdHoc::FormatterDetail::__FMT, sizeof...(t)>(); + } +#endif +#ifdef __clang__ +#pragma clang diagnostic pop +#endif + } } #endif -- cgit v1.2.3