summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libadhocutil/compileTimeFormatter.h6
-rw-r--r--libadhocutil/unittests/testCompileTimeFormatter.cpp7
2 files changed, 13 insertions, 0 deletions
diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h
index 631b0f7..7734f9c 100644
--- a/libadhocutil/compileTimeFormatter.h
+++ b/libadhocutil/compileTimeFormatter.h
@@ -213,3 +213,9 @@ namespace AdHoc {
};
}
+#define AdHocFormatterTypedef(name, str, id) \
+ extern constexpr auto id = str; \
+ typedef ::AdHoc::Formatter<id> name
+#define AdHocFormatter(name, str) \
+ AdHocFormatterTypedef(name, str, name ## __COUNTER__)
+
diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp
index df0d93c..030dbc9 100644
--- a/libadhocutil/unittests/testCompileTimeFormatter.cpp
+++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp
@@ -196,6 +196,13 @@ BOOST_AUTO_TEST_CASE ( typedefFormat )
BOOST_REQUIRE_EQUAL(this->str(), "custom -( expr )-");
}
+AdHocFormatter(TypedefWrapper, "Typedef wrapper %?.");
+BOOST_AUTO_TEST_CASE ( typedefWrapper )
+{
+ TypedefWrapper::write(*this, "expr");
+ BOOST_REQUIRE_EQUAL(this->str(), "Typedef wrapper expr.");
+}
+
BOOST_AUTO_TEST_CASE ( longFormatString )
{
Formatter<formatStringLong>::write(*this);