]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/format.h
Use variadic templates for format and print functions if available
[libs/core.git] / source / strings / format.h
index 65d10dffa585bb6e272db7d1d20a71a07b6a0a42..7bd8264f2407495d4c306501e6979703eb4740e5 100644 (file)
@@ -29,6 +29,14 @@ public:
                return *this;
        }
 
+#if __cplusplus>=201103L
+       template<typename T, typename... Tail>
+       Formatter &operator()(const T &a, const Tail &... tail)
+       {
+               return (*this)(a)(tail...);
+       }
+#endif
+
        /** 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,6 +55,14 @@ private:
 inline Formatter format(const std::string &f)
 { return Formatter(f); }
 
+#if __cplusplus >= 201103L
+template<typename... Args>
+inline std::string format(const std::string &f, const Args &... args)
+{
+       return Formatter(f)(args...).str();
+}
+
+#else
 template<typename A1>
 inline std::string format(const std::string &f, const A1 &a1)
 { return Formatter(f)(a1).str(); }
@@ -66,6 +82,7 @@ inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, cons
 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(); }
+#endif
 
 } // namespace Msp