summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2019-02-04 23:31:54 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2019-02-04 23:31:54 +0000
commit52c9ac16c11ccb8abc987b0bad3a4d93aa3bdfc8 (patch)
treea5dd8726b1f4a27a5ea987a2f1428f279146d2b8
parentRemove calls to naked new (diff)
downloadlibadhocutil-52c9ac16c11ccb8abc987b0bad3a4d93aa3bdfc8.tar.bz2
libadhocutil-52c9ac16c11ccb8abc987b0bad3a4d93aa3bdfc8.tar.xz
libadhocutil-52c9ac16c11ccb8abc987b0bad3a4d93aa3bdfc8.zip
Explicitly disable stream operator() of formatterlibadhocutil-0.7.0
When stream type does not have a write member, prevents failure when overload matches call because first argument can passed by non-const reference.
-rw-r--r--libadhocutil/compileTimeFormatter.h3
-rw-r--r--libadhocutil/unittests/testCompileTimeFormatter.cpp6
2 files changed, 8 insertions, 1 deletions
diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h
index 562c511..9dae0ef 100644
--- a/libadhocutil/compileTimeFormatter.h
+++ b/libadhocutil/compileTimeFormatter.h
@@ -166,7 +166,8 @@ namespace AdHoc {
* @return the stream.
*/
template<typename stream, typename ... Pn>
- inline stream & operator()(stream & s, const Pn & ... pn) const
+ inline typename std::enable_if<(bool)&stream::write, stream>::type &
+ operator()(stream & s, const Pn & ... pn) const
{
return write(s, pn...);
}
diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp
index b02eadd..7313252 100644
--- a/libadhocutil/unittests/testCompileTimeFormatter.cpp
+++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp
@@ -465,6 +465,12 @@ BOOST_AUTO_TEST_CASE(user_defined_literal_fmt_get)
BOOST_CHECK_EQUAL("foo 42", "foo %?"_fmt(42));
}
+BOOST_AUTO_TEST_CASE(user_defined_literal_fmt_get_reference)
+{
+ int x = 42;
+ BOOST_CHECK_EQUAL("foo 42", "foo %?"_fmt(x));
+}
+
BOOST_AUTO_TEST_CASE(user_defined_literal_fmt_write)
{
std::stringstream str;