diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-12-30 18:18:07 +0000 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-12-30 18:18:07 +0000 | 
| commit | d41521337e55e21da69d7c4e99bf95a792ba8ad8 (patch) | |
| tree | 48ebe56c5fdb7cf128211524d7c464ca3e4190a0 | |
| parent | Add helper for simply returning a formatted string (sprintf style) (diff) | |
| download | libadhocutil-d41521337e55e21da69d7c4e99bf95a792ba8ad8.tar.bz2 libadhocutil-d41521337e55e21da69d7c4e99bf95a792ba8ad8.tar.xz libadhocutil-d41521337e55e21da69d7c4e99bf95a792ba8ad8.zip  | |
Return stream to ease inlining
| -rw-r--r-- | libadhocutil/compileTimeFormatter.h | 10 | ||||
| -rw-r--r-- | libadhocutil/unittests/testCompileTimeFormatter.cpp | 5 | 
2 files changed, 10 insertions, 5 deletions
diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h index 8a92094..aeff488 100644 --- a/libadhocutil/compileTimeFormatter.h +++ b/libadhocutil/compileTimeFormatter.h @@ -176,20 +176,20 @@ namespace AdHoc {  		static std::string get(const Pn & ... pn)  		{  			std::stringstream s; -			run(Parser<S, 0, 0, *S>::parse(), s, pn...); -			return s.str(); +			return run(Parser<S, 0, 0, *S>::parse(), s, pn...).str();  		}  		template<typename stream, typename ... Pn> -		static void write(stream & s, const Pn & ... pn) +		static stream & write(stream & s, const Pn & ... pn)  		{ -			run(Parser<S, 0, 0, *S>::parse(), s, pn...); +			return run(Parser<S, 0, 0, *S>::parse(), s, pn...);  		}  		template<typename stream, char...ssn, template<bool, char...> class ParserBuffer, typename ... Pn> -		static void run(const ParserBuffer<false, ssn...> &, stream & s, const Pn & ... pn) +		static stream & run(const ParserBuffer<false, ssn...> &, stream & s, const Pn & ... pn)  		{  			StreamWriter<S, 0, stream, ssn...>::write(s, pn...); +			return s;  		}  	};  } diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp index 0f021e5..df0d93c 100644 --- a/libadhocutil/unittests/testCompileTimeFormatter.cpp +++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp @@ -117,6 +117,11 @@ BOOST_AUTO_TEST_CASE ( singleInt )  	BOOST_REQUIRE_EQUAL(this->str(), "single 32.");  } +BOOST_AUTO_TEST_CASE ( singleIntReturn ) +{ +	BOOST_REQUIRE_EQUAL(Formatter<formatStringSingle>::write(*this, 32).str(), "single 32."); +} +  BOOST_AUTO_TEST_CASE ( singleDouble )  {  	Formatter<formatStringSingle>::write(*this, 3.14);  | 
