3 This file is part of libmspstrings
4 Copyright © 2006-2007 Mikko Rasa
5 Distributed under the LGPL
8 #ifndef MSP_STRINGS_FORMAT_H_
9 #define MSP_STRINGS_FORMAT_H_
12 #include "lexicalcast.h"
17 Printf-like string formatter class.
23 std::string::iterator pos;
27 Formatter(const std::string &);
29 /** Extracts the next conversion from the format string and formats the
30 given value with it. Will throw if no more conversions are found. */
32 Formatter &operator()(const T &a)
34 result += lexical_cast(a, get_conversion());
39 const std::string &str() const;
45 inline Formatter format(const std::string &f)
46 { return Formatter(f); }
49 inline std::string format(const std::string &f, const A1 &a1)
50 { return Formatter(f)(a1).str(); }
52 template<typename A1, typename A2>
53 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2)
54 { return Formatter(f)(a1)(a2).str(); }
56 template<typename A1, typename A2, typename A3>
57 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3)
58 { return Formatter(f)(a1)(a2)(a3).str(); }
60 template<typename A1, typename A2, typename A3, typename A4>
61 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
62 { return Formatter(f)(a1)(a2)(a3)(a4).str(); }
64 template<typename A1, typename A2, typename A3, typename A4, typename A5>
65 inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5)
66 { return Formatter(f)(a1)(a2)(a3)(a4)(a5).str(); }