1 #ifndef MSP_STRINGS_FORMAT_H_
2 #define MSP_STRINGS_FORMAT_H_
5 #include "lexicalcast.h"
10 Printf-like string formatter class.
16 std::string::iterator pos;
20 Formatter(const std::string &);
22 /** Extracts the next conversion from the format string and formats the
23 given value with it. Will throw if no more conversions are found. */
25 Formatter &operator()(const T &a)
27 result += lexical_cast(a, get_conversion());
32 const std::string &str() const;
38 inline Formatter format(const std::string &f)
39 { return Formatter(f); }
42 inline std::string format(const std::string &f, const A1 &a1)
43 { return Formatter(f)(a1).str(); }
45 template<typename A1, typename A2>
46 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2)
47 { return Formatter(f)(a1)(a2).str(); }
49 template<typename A1, typename A2, typename A3>
50 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3)
51 { return Formatter(f)(a1)(a2)(a3).str(); }
53 template<typename A1, typename A2, typename A3, typename A4>
54 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
55 { return Formatter(f)(a1)(a2)(a3)(a4).str(); }
57 template<typename A1, typename A2, typename A3, typename A4, typename A5>
58 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5)
59 { return Formatter(f)(a1)(a2)(a3)(a4)(a5).str(); }