diff options
author | Ben Burdette <bburdette@gmail.com> | 2020-04-03 08:48:20 -0600 |
---|---|---|
committer | Ben Burdette <bburdette@gmail.com> | 2020-04-03 08:48:20 -0600 |
commit | 7b7801d3f0e0e1cd32b1279979970ad71b66b879 (patch) | |
tree | 572ea5c1870c0ef2196644e1b23dfed8fcfe9f6d /src/libutil/error.hh | |
parent | c6b3fcddb0d05718ec11807ad847d7bf60cc703f (diff) |
variadic args for hint format
Diffstat (limited to 'src/libutil/error.hh')
-rw-r--r-- | src/libutil/error.hh | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/libutil/error.hh b/src/libutil/error.hh index 70884c189..1c5d6d13c 100644 --- a/src/libutil/error.hh +++ b/src/libutil/error.hh @@ -7,6 +7,7 @@ #include <iostream> #include <iomanip> +#include "types.hh" #include <boost/format.hpp> namespace nix @@ -234,7 +235,7 @@ protected: // ---------------------------------------------------------------- -// format for hints. same as boost format, except templated values +// format for hints. same as fmt, except templated values // are always in yellow. template <class T> @@ -251,20 +252,25 @@ std::ostream& operator<<(std::ostream &out, const yellowify<T> &y) return out << ANSI_YELLOW << y.value << ANSI_NORMAL; } -class hintfmt +class hintformat { public: - hintfmt(string format) :fmt(format) + hintformat(string format) :fmt(format) { fmt.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit); } template<class T> - hintfmt& operator%(const T &value) + hintformat& operator%(const T &value) { fmt % yellowify(value); return *this; } + std::string str() const + { + return fmt.str(); + } + template <typename U> friend class AddHint; private: @@ -272,14 +278,22 @@ private: }; +template<typename... Args> +inline hintformat hintfmt(const std::string & fs, const Args & ... args) +{ + hintformat f(fs); + formatHelper(f, args...); + return f; +} + // the template layer for adding a hint. template <class T> class AddHint : private T { public: - T& hint(hintfmt &hfmt) + T& hint(const hintformat &hf) { - GetEI().hint = std::optional(hfmt.fmt.str()); + GetEI().hint = std::optional(hf.str()); return *this; } T& nohint() |