1 #ifndef MSP_STRINGS_FORMATTER_H_
2 #define MSP_STRINGS_FORMATTER_H_
5 #include "lexicalcast.h"
10 Printf-like string formatter class.
15 Formatter(const std::string &);
18 Extracts the next conversion from the format string and formats the given
19 value with it. Will throw if no more conversions are found.
22 Formatter &operator()(const T &a)
24 result+=lexical_cast(a, get_conversion());
29 const std::string &str() const;
32 std::string::iterator pos;
39 inline Formatter format(const std::string &f)
40 { return Formatter(f); }
43 inline std::string format(const std::string &f, const A1 &a1)
44 { return Formatter(f)(a1).str(); }
46 template<typename A1, typename A2>
47 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2)
48 { return Formatter(f)(a1)(a2).str(); }
50 template<typename A1, typename A2, typename A3>
51 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3)
52 { return Formatter(f)(a1)(a2)(a3).str(); }
54 template<typename A1, typename A2, typename A3, typename A4>
55 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
56 { return Formatter(f)(a1)(a2)(a3)(a4).str(); }
58 template<typename A1, typename A2, typename A3, typename A4, typename A5>
59 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5)
60 { return Formatter(f)(a1)(a2)(a3)(a4)(a5).str(); }