summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-09-04 22:19:30 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2018-09-04 22:19:30 +0100
commit7f6089b5f63c936715e042515269842c56c7de04 (patch)
tree53080bd8249505ad70a5d91aec1891b39cf49975
parentUpdate install to reflect moved ctf impls (diff)
downloadlibadhocutil-7f6089b5f63c936715e042515269842c56c7de04.tar.bz2
libadhocutil-7f6089b5f63c936715e042515269842c56c7de04.tar.xz
libadhocutil-7f6089b5f63c936715e042515269842c56c7de04.zip
scprintf macro with non-variable
Updates scprintf macro to handle the case where strm isn't a variable and thus cannot be captured, instead passing it as a parameter to the lambda.
-rw-r--r--libadhocutil/compileTimeFormatter.h8
-rw-r--r--libadhocutil/unittests/testCompileTimeFormatter.cpp8
2 files changed, 8 insertions, 8 deletions
diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h
index 2fc193e..35dffde 100644
--- a/libadhocutil/compileTimeFormatter.h
+++ b/libadhocutil/compileTimeFormatter.h
@@ -190,11 +190,11 @@ namespace AdHoc {
// As far as I know, only clang/llvm version 5+ can compile this
// so long as std=c++17
#if __clang_major__ >= 5 && __cplusplus >= 201703
-#define scprintf(strm, fmt, ...) \
- ([&strm]() -> decltype(strm) & { \
- static constexpr const char * const __FMT = fmt; \
+#define scprintf(strmp, fmt, ...) \
+ ([](decltype(strmp) & strm) -> auto & { \
+ static constexpr auto __FMT = fmt; \
return ::AdHoc::Formatter<__FMT>::write(strm, __VA_ARGS__); \
- }())
+ }(strmp))
#endif
#endif
diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp
index b966078..9bb81f6 100644
--- a/libadhocutil/unittests/testCompileTimeFormatter.cpp
+++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp
@@ -450,10 +450,10 @@ BOOST_AUTO_TEST_CASE(smartptr)
#ifdef scprintf
BOOST_AUTO_TEST_CASE(scprintf)
{
- std::stringstream str;
- auto & strret = scprintf(str, "Some literal format string (%d, %c).", 0, 'f');
- BOOST_CHECK_EQUAL(&str, &strret); // We got back our original stream
- BOOST_CHECK_EQUAL(str.str(), "Some literal format string (0, f).");
+ auto str = std::make_unique<std::stringstream>();
+ auto & strret = scprintf(*str, "Some literal format string (%d, %c).", 0, 'f');
+ BOOST_CHECK_EQUAL(str.get(), &strret); // We got back our original stream
+ BOOST_CHECK_EQUAL(str->str(), "Some literal format string (0, f).");
}
#endif