diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-05-11 17:06:07 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-05-15 17:36:32 +0200 |
commit | 2b761d5f50b7dc17dc55c31980c2253c37b3c920 (patch) | |
tree | 48fa396d4ddc2eb7348c213dbd59c08404ca64e3 /src | |
parent | 0124d118ef6718716f740ebfd3ae5eff0453be9e (diff) |
Make fmt() non-recursive
Diffstat (limited to 'src')
-rw-r--r-- | src/libutil/logging.hh | 2 | ||||
-rw-r--r-- | src/libutil/types.hh | 17 |
2 files changed, 7 insertions, 12 deletions
diff --git a/src/libutil/logging.hh b/src/libutil/logging.hh index 81aebccdc..a8c69dbd9 100644 --- a/src/libutil/logging.hh +++ b/src/libutil/logging.hh @@ -88,7 +88,7 @@ template<typename... Args> inline void warn(const std::string & fs, Args... args) { boost::format f(fs); - formatHelper(f, args...); + nop{boost::io::detail::feed(f, args)...}; logger->warn(f.str()); } diff --git a/src/libutil/types.hh b/src/libutil/types.hh index 1429c2385..9f32d31ad 100644 --- a/src/libutil/types.hh +++ b/src/libutil/types.hh @@ -32,6 +32,11 @@ using std::vector; using boost::format; +/* A variadic template that does nothing. Useful to call a function + for all variadic arguments but ignoring the result. */ +struct nop { template<typename... T> nop(T...) {} }; + + struct FormatOrString { string s; @@ -46,16 +51,6 @@ struct FormatOrString ... a_n’. However, ‘fmt(s)’ is equivalent to ‘s’ (so no %-expansion takes place). */ -inline void formatHelper(boost::format & f) -{ -} - -template<typename T, typename... Args> -inline void formatHelper(boost::format & f, T x, Args... args) -{ - formatHelper(f % x, args...); -} - inline std::string fmt(const std::string & s) { return s; @@ -75,7 +70,7 @@ template<typename... Args> inline std::string fmt(const std::string & fs, Args... args) { boost::format f(fs); - formatHelper(f, args...); + nop{boost::io::detail::feed(f, args)...}; return f.str(); } |