summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2020-03-22 10:51:04 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2020-03-28 13:22:40 +0000
commit5017d39cd942f99400c1a967b96459fde162f934 (patch)
tree1cfd4337bfe17ee35d767afca0bf8ec7d1e966ad
parentFixes for tidy (diff)
downloadlibadhocutil-5017d39cd942f99400c1a967b96459fde162f934.tar.bz2
libadhocutil-5017d39cd942f99400c1a967b96459fde162f934.tar.xz
libadhocutil-5017d39cd942f99400c1a967b96459fde162f934.zip
Macro CtfString type
-rw-r--r--libadhocutil/compileTimeFormatter.h23
-rw-r--r--libadhocutil/ctf-impl/printf-compat.h4
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<typename char_type>
constexpr bool isdigit(const char_type & ch)
@@ -22,7 +23,7 @@ namespace AdHoc {
}
// Template string utils
- template<const auto & S>
+ template<CtfString S>
static constexpr auto strlen()
{
auto off = 0;
@@ -30,7 +31,7 @@ namespace AdHoc {
return off;
}
- template<const auto & S, auto n, auto start = 0, auto L = strlen<S>()>
+ template<CtfString S, auto n, auto start = 0, auto L = strlen<S>()>
static constexpr auto strchr()
{
static_assert(start <= L);
@@ -42,7 +43,7 @@ namespace AdHoc {
return off;
}
- template<const auto & S, auto n, auto start = 0, auto L = strlen<S>()>
+ template<CtfString S, auto n, auto start = 0, auto L = strlen<S>()>
static constexpr decltype(L) strchrnul()
{
decltype(start) off = start;
@@ -50,10 +51,10 @@ namespace AdHoc {
return off;
}
- template <const auto & S, decltype(strlen<S>())> class Formatter;
+ template<CtfString S, decltype(strlen<S>())> class Formatter;
/// Template used to apply parameters to a stream.
- template<const auto & S, auto L, auto pos, typename stream, typename, auto ...>
+ template<CtfString S, auto L, auto pos, typename stream, typename, auto ...>
struct StreamWriter {
/// Write parameters to stream.
template<typename ... Pn>
@@ -64,7 +65,7 @@ namespace AdHoc {
};
/// Helper to simplify implementations of StreamWriter.
- template<const auto & S, auto L, auto pos, typename stream>
+ template<CtfString S, auto L, auto pos, typename stream>
struct StreamWriterBase {
/// Continue processing parameters.
template<typename ... Pn>
@@ -75,12 +76,12 @@ namespace AdHoc {
};
#define StreamWriterT(C...) \
- template<const auto & S, auto L, auto pos, typename stream, auto ... sn> \
+ template<CtfString S, auto L, auto pos, typename stream, auto ... sn> \
struct StreamWriter<S, L, pos, stream, void, '%', C, sn...> : \
public StreamWriterBase<S, L, BOOST_PP_VARIADIC_SIZE(C) + pos, stream>
#define StreamWriterTP(P, C...) \
- template<const auto & S, auto L, auto pos, typename stream, auto P, auto ... sn> \
+ template<CtfString S, auto L, auto pos, typename stream, auto P, auto ... sn> \
struct StreamWriter<S, L, pos, stream, void, '%', C, sn...> : \
public StreamWriterBase<S, L, BOOST_PP_VARIADIC_SIZE(C) + pos, stream>
@@ -120,11 +121,11 @@ namespace AdHoc {
* Compile time string formatter.
* @param S the format string.
*/
- template <const auto & S, decltype(strlen<S>()) L = strlen<S>()>
+ template <CtfString S, decltype(strlen<S>()) L = strlen<S>()>
class Formatter {
private:
using strlen_t = decltype(strlen<S>());
- template<const auto &, auto, auto, typename> friend struct StreamWriterBase;
+ template<CtfString, auto, auto, typename> 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<id> name
+ using name = ::AdHoc::Formatter<id>
#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<const auto & S, auto L, auto pos, typename stream, BOOST_PP_REPEAT(BOOST_PP_ADD(d, 1), AUTON, n), auto nn, auto ... sn> \
+ template<CtfString S, auto L, auto pos, typename stream, BOOST_PP_REPEAT(BOOST_PP_ADD(d, 1), AUTON, n), auto nn, auto ... sn> \
struct StreamWriter<S, L, pos, stream, typename std::enable_if<ispositivedigit(n0) BOOST_PP_REPEAT(d, ISDIGIT, n) && !isdigit(nn)>::type, '%', BOOST_PP_REPEAT(BOOST_PP_ADD(d, 1), NS, n), nn, sn...> { \
template<typename ... Pn> \
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<const auto & S, auto L, auto pos, typename stream, BOOST_PP_REPEAT(BOOST_PP_ADD(d, 1), AUTON, n), auto nn, auto ... sn> \
+ template<CtfString S, auto L, auto pos, typename stream, BOOST_PP_REPEAT(BOOST_PP_ADD(d, 1), AUTON, n), auto nn, auto ... sn> \
struct StreamWriter<S, L, pos, stream, typename std::enable_if<isdigit(n0) BOOST_PP_REPEAT(d, ISDIGIT, n) && !isdigit(nn)>::type, '%', '.', BOOST_PP_REPEAT(BOOST_PP_ADD(d, 1), NS, n), nn, sn...> { \
template<typename ... Pn> \
static inline void write(stream & s, const Pn & ... pn) { \