X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstrings%2Fformat.h;h=7bd8264f2407495d4c306501e6979703eb4740e5;hb=71be32fe7248a7d2df7dea4e18c5ebd30fd73d4b;hp=db74bf9560788f3bbce4b0673cd5f7b3076ba2fc;hpb=3a965c87750250c8facc9dbff02aeb3a88e19f05;p=libs%2Fcore.git diff --git a/source/strings/format.h b/source/strings/format.h index db74bf9..7bd8264 100644 --- a/source/strings/format.h +++ b/source/strings/format.h @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspstrings -Copyright © 2006-2007 Mikko Rasa -Distributed under the LGPL -*/ - #ifndef MSP_STRINGS_FORMAT_H_ #define MSP_STRINGS_FORMAT_H_ @@ -31,20 +24,45 @@ public: template Formatter &operator()(const T &a) { - result += lexical_cast(a, get_conversion()); + result += lexical_cast(a, get_conversion()); advance(); return *this; } +#if __cplusplus>=201103L + template + 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; + private: + /** Advances the iterator to the next conversion, adding literal characters + to the result. The iterator is left at the second character of the + conversion (i.e. after the %). */ void advance(); + + /** Reads the next conversion from the format string and returns a + corresponding Fmt object. */ Fmt get_conversion(); }; inline Formatter format(const std::string &f) { return Formatter(f); } +#if __cplusplus >= 201103L +template +inline std::string format(const std::string &f, const Args &... args) +{ + return Formatter(f)(args...).str(); +} + +#else template inline std::string format(const std::string &f, const A1 &a1) { return Formatter(f)(a1).str(); } @@ -64,6 +82,7 @@ inline std::string format(const std::string &f, const A1 &a1, const A2 &a2, cons template 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