diff options
-rw-r--r-- | libadhocutil/compileTimeFormatter.h | 10 | ||||
-rw-r--r-- | libadhocutil/unittests/testCompileTimeFormatter.cpp | 6 |
2 files changed, 15 insertions, 1 deletions
diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h index 9f6acfe..8a92094 100644 --- a/libadhocutil/compileTimeFormatter.h +++ b/libadhocutil/compileTimeFormatter.h @@ -1,4 +1,4 @@ -#include <iostream> +#include <sstream> #include <string.h> #include <boost/static_assert.hpp> #include <boost/preprocessor/variadic/size.hpp> @@ -172,6 +172,14 @@ namespace AdHoc { template <const char * const & S> struct Formatter { + template<typename ... Pn> + static std::string get(const Pn & ... pn) + { + std::stringstream s; + run(Parser<S, 0, 0, *S>::parse(), s, pn...); + return s.str(); + } + template<typename stream, typename ... Pn> static void write(stream & s, const Pn & ... pn) { diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp index 9b678ec..0f021e5 100644 --- a/libadhocutil/unittests/testCompileTimeFormatter.cpp +++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp @@ -211,3 +211,9 @@ BOOST_AUTO_TEST_CASE ( customMultiArgRightAlign ) BOOST_REQUIRE_EQUAL(buf3.str(), "value 123.45"); } +BOOST_AUTO_TEST_CASE ( get ) +{ + auto s = Formatter<formatStringMultiArg>::get(20, "something else"); + BOOST_REQUIRE_EQUAL(s, "value something else"); +} + |