]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/format.h
Require C++11 for building
[libs/core.git] / source / strings / format.h
index 6d8f739a436c3abaa8fdbbbdc7292e5dfb803d1d..49c40e9293512da2a656699d837f7f42834771c6 100644 (file)
@@ -18,17 +18,25 @@ private:
 
 public:
        Formatter(const std::string &);
+       Formatter(const Formatter &);
+       Formatter &operator=(const Formatter &);
 
        /** Extracts the next conversion from the format string and formats the
        given value with it.  Will throw if no more conversions are found. */
        template<typename T>
        Formatter &operator()(const T &a)
        {
-               result += lexical_cast(a, get_conversion());
+               result += lexical_cast<std::string>(a, get_conversion());
                advance();
                return *this;
        }
 
+       template<typename T, typename... Tail>
+       Formatter &operator()(const T &a, const Tail &... tail)
+       {
+               return (*this)(a)(tail...);
+       }
+
        /** Returns the result of the formatting operation.  Will throw if not
        enough values have been fed to the formatter. */
        const std::string &str() const;
@@ -47,25 +55,11 @@ private:
 inline Formatter format(const std::string &f)
 { return Formatter(f); }
 
-template<typename A1>
-inline std::string format(const std::string &f, const A1 &a1)
-{ return Formatter(f)(a1).str(); }
-
-template<typename A1, typename A2>
-inline std::string format(const std::string &f, const A1 &a1, const A2 &a2)
-{ return Formatter(f)(a1)(a2).str(); }
-
-template<typename A1, typename A2, typename A3>
-inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3)
-{ return Formatter(f)(a1)(a2)(a3).str(); }
-
-template<typename A1, typename A2, typename A3, typename A4>
-inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
-{ return Formatter(f)(a1)(a2)(a3)(a4).str(); }
-
-template<typename A1, typename A2, typename A3, typename A4, typename A5>
-inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5)
-{ return Formatter(f)(a1)(a2)(a3)(a4)(a5).str(); }
+template<typename... Args>
+inline std::string format(const std::string &f, const Args &... args)
+{
+       return Formatter(f)(args...).str();
+}
 
 } // namespace Msp