From 5017d39cd942f99400c1a967b96459fde162f934 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 22 Mar 2020 10:51:04 +0000 Subject: Macro CtfString type --- libadhocutil/compileTimeFormatter.h | 23 ++++++++++++----------- libadhocutil/ctf-impl/printf-compat.h | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h index ba243c6..09fdb6a 100644 --- a/libadhocutil/compileTimeFormatter.h +++ b/libadhocutil/compileTimeFormatter.h @@ -8,6 +8,7 @@ #include "unique.h" namespace AdHoc { +#define CtfString const auto & // Template char utils template constexpr bool isdigit(const char_type & ch) @@ -22,7 +23,7 @@ namespace AdHoc { } // Template string utils - template + template static constexpr auto strlen() { auto off = 0; @@ -30,7 +31,7 @@ namespace AdHoc { return off; } - template()> + template()> static constexpr auto strchr() { static_assert(start <= L); @@ -42,7 +43,7 @@ namespace AdHoc { return off; } - template()> + template()> static constexpr decltype(L) strchrnul() { decltype(start) off = start; @@ -50,10 +51,10 @@ namespace AdHoc { return off; } - template ())> class Formatter; + template())> class Formatter; /// Template used to apply parameters to a stream. - template + template struct StreamWriter { /// Write parameters to stream. template @@ -64,7 +65,7 @@ namespace AdHoc { }; /// Helper to simplify implementations of StreamWriter. - template + template struct StreamWriterBase { /// Continue processing parameters. template @@ -75,12 +76,12 @@ namespace AdHoc { }; #define StreamWriterT(C...) \ - template \ + template \ struct StreamWriter : \ public StreamWriterBase #define StreamWriterTP(P, C...) \ - template \ + template \ struct StreamWriter : \ public StreamWriterBase @@ -120,11 +121,11 @@ namespace AdHoc { * Compile time string formatter. * @param S the format string. */ - template ()) L = strlen()> + template ()) L = strlen()> class Formatter { private: using strlen_t = decltype(strlen()); - template friend struct StreamWriterBase; + template friend struct StreamWriterBase; public: /// The derived charater type of the format string. @@ -229,7 +230,7 @@ namespace AdHoc { #define AdHocFormatterTypedef(name, str, id) \ inline constexpr auto id = str; \ - typedef ::AdHoc::Formatter name + using name = ::AdHoc::Formatter #define AdHocFormatter(name, str) \ AdHocFormatterTypedef(name, str, MAKE_UNIQUE(name)) diff --git a/libadhocutil/ctf-impl/printf-compat.h b/libadhocutil/ctf-impl/printf-compat.h index ca82725..4f93d4f 100644 --- a/libadhocutil/ctf-impl/printf-compat.h +++ b/libadhocutil/ctf-impl/printf-compat.h @@ -118,7 +118,7 @@ namespace AdHoc { #define NS(z, n, data) BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(data, n) #define ISDIGIT(z, n, data) && isdigit(BOOST_PP_CAT(data, BOOST_PP_ADD(n, 1))) #define FMTWIDTH(unused, d, data) \ - template \ + template \ struct StreamWriter::type, '%', BOOST_PP_REPEAT(BOOST_PP_ADD(d, 1), NS, n), nn, sn...> { \ template \ static inline void write(stream & s, const Pn & ... pn) { \ @@ -129,7 +129,7 @@ namespace AdHoc { }; BOOST_PP_REPEAT(6, FMTWIDTH, void); #define FMTPRECISION(unused, d, data) \ - template \ + template \ struct StreamWriter::type, '%', '.', BOOST_PP_REPEAT(BOOST_PP_ADD(d, 1), NS, n), nn, sn...> { \ template \ static inline void write(stream & s, const Pn & ... pn) { \ -- cgit v1.2.3