summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2020-03-28 14:22:21 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2020-03-28 14:22:21 +0000
commit2c5d82a7c0762c242f2ef1bcd902a17c0fbd9515 (patch)
tree6f2ff7591acf8e41cf45d29a92e6c26429217383
parentAdd [s]cprintf functions (diff)
downloadlibadhocutil-2c5d82a7c0762c242f2ef1bcd902a17c0fbd9515.tar.bz2
libadhocutil-2c5d82a7c0762c242f2ef1bcd902a17c0fbd9515.tar.xz
libadhocutil-2c5d82a7c0762c242f2ef1bcd902a17c0fbd9515.zip
Simplify fmt literal with basic_fixed_string
-rw-r--r--libadhocutil/compileTimeFormatter.h50
1 files 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<typename T, T ... t> struct FMT
- {
- /// CTF format string
- // NOLINTNEXTLINE(hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
- static constexpr char __FMT[] = {t...};
- };
- template<typename T, T ... t> inline auto operator""_fmt() noexcept
- {
- return AdHoc::FormatterDetail<FMT<T, t...>::__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<const support::basic_fixed_string Str>
+ constexpr inline auto operator""_fmt() noexcept
+ {
+ return AdHoc::FormatterDetail<Str, Str.size()>();
+ }
+#else
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template"
+#endif
+ /// CTF format string holder
+ template<typename T, T ... t> struct FMT
+ {
+ /// CTF format string
+ // NOLINTNEXTLINE(hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
+ static constexpr char __FMT[] = {t...};
+ };
+ template<typename T, T ... t> inline auto operator""_fmt() noexcept
+ {
+ return AdHoc::FormatterDetail<FMT<T, t...>::__FMT, sizeof...(t)>();
+ }
+#endif
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+ }
}
#endif