From 75f5d2a139a886178a88c704770f62de84d2ef84 Mon Sep 17 00:00:00 2001 From: Daniel Boles Date: Fri, 1 Sep 2017 12:47:08 +0100 Subject: =?UTF-8?q?ustring:=20Replace=208=C3=97format()=20with=201=20varia?= =?UTF-8?q?dic=20template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit as per the previous commit for Glib::ustring. Now, users can pass format() as many arguments as their compiler or stack will allow, rather than being limited to a maximum of 8. https://bugzilla.gnome.org/show_bug.cgi?id=784211 --- glib/glibmm/ustring.h | 176 +++++++------------------------------------------- 1 file changed, 23 insertions(+), 153 deletions(-) diff --git a/glib/glibmm/ustring.h b/glib/glibmm/ustring.h index dd0423f3..dd23a885 100644 --- a/glib/glibmm/ustring.h +++ b/glib/glibmm/ustring.h @@ -668,7 +668,7 @@ public: template static inline ustring compose(const ustring& fmt, const Ts&... args); - /*! Format the argument to its string representation. + /*! Format the argument(s) to a string representation. * Applies the arguments in order to an std::wostringstream and returns the * resulting string. I/O manipulators may also be used as arguments. This * greatly simplifies the common task of converting a number to a string, as @@ -692,67 +692,15 @@ public: * ustring text = ustring::format(std::setfill(L'0'), std::setw(6), 123); * @endcode * - * @param a1 A streamable value or an I/O manipulator. + * @param args One or more streamable values or I/O manipulators. * @return The string representation of the argument stream. * @throw Glib::ConvertError * - * @newin{2,16} - */ - template - static inline ustring format(const T1& a1); - - /* See the documentation for format(const T1& a1). - * - * @newin{2,16} - */ - template - static inline ustring format(const T1& a1, const T2& a2); - - /* See the documentation for format(const T1& a1). - * - * @newin{2,16} - */ - template - static inline ustring format(const T1& a1, const T2& a2, const T3& a3); - - /* See the documentation for format(const T1& a1). - * - * @newin{2,16} - */ - template - static inline ustring format(const T1& a1, const T2& a2, const T3& a3, const T4& a4); - - /* See the documentation for format(const T1& a1). - * - * @newin{2,16} - */ - template - static inline ustring format( - const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5); - - /* See the documentation for format(const T1& a1). - * - * @newin{2,16} - */ - template - static inline ustring format( - const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6); - - /* See the documentation for format(const T1& a1). - * - * @newin{2,16} + * @newin{2,56} */ - template - static inline ustring format(const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, - const T6& a6, const T7& a7); + template + static inline ustring format(const Ts&... args); - /* See the documentation for format(const T1& a1). - * - * @newin{2,16} - */ - template - static inline ustring format(const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, - const T6& a6, const T7& a7, const T8& a8); //! @} private: @@ -775,9 +723,15 @@ private: template class Stringify; + static ustring compose_private(const ustring& fmt, std::initializer_list ilist); + class FormatStream; - static ustring compose_private(const ustring& fmt, std::initializer_list ilist); + template + static inline void format_private(FormatStream& buf, const T& arg); + + template + static inline void format_private(FormatStream& buf, const T1& a1, const Ts&... args); #endif /* DOXYGEN_SHOULD_SKIP_THIS */ @@ -1092,114 +1046,30 @@ ustring::raw() const return string_; } -template -inline // static - ustring - ustring::format(const T1& a1) -{ - ustring::FormatStream buf; - buf.stream(a1); - return buf.to_string(); -} - -template -inline // static - ustring - ustring::format(const T1& a1, const T2& a2) -{ - ustring::FormatStream buf; - buf.stream(a1); - buf.stream(a2); - return buf.to_string(); -} - -template -inline // static - ustring - ustring::format(const T1& a1, const T2& a2, const T3& a3) -{ - ustring::FormatStream buf; - buf.stream(a1); - buf.stream(a2); - buf.stream(a3); - return buf.to_string(); -} - -template -inline // static - ustring - ustring::format(const T1& a1, const T2& a2, const T3& a3, const T4& a4) -{ - ustring::FormatStream buf; - buf.stream(a1); - buf.stream(a2); - buf.stream(a3); - buf.stream(a4); - return buf.to_string(); -} - -template +template inline // static - ustring - ustring::format(const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5) + void + ustring::format_private(FormatStream& buf, const T& arg) { - ustring::FormatStream buf; - buf.stream(a1); - buf.stream(a2); - buf.stream(a3); - buf.stream(a4); - buf.stream(a5); - return buf.to_string(); + buf.stream(arg); } -template +template inline // static - ustring - ustring::format( - const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, const T6& a6) + void + ustring::format_private(FormatStream& buf, const T1& a1, const Ts&... args) { - ustring::FormatStream buf; buf.stream(a1); - buf.stream(a2); - buf.stream(a3); - buf.stream(a4); - buf.stream(a5); - buf.stream(a6); - return buf.to_string(); + return format_private(buf, args...); } -template -inline // static - ustring - ustring::format(const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, - const T6& a6, const T7& a7) -{ - ustring::FormatStream buf; - buf.stream(a1); - buf.stream(a2); - buf.stream(a3); - buf.stream(a4); - buf.stream(a5); - buf.stream(a6); - buf.stream(a7); - return buf.to_string(); -} - -template +template inline // static ustring - ustring::format(const T1& a1, const T2& a2, const T3& a3, const T4& a4, const T5& a5, - const T6& a6, const T7& a7, const T8& a8) + ustring::format(const Ts&... args) { ustring::FormatStream buf; - buf.stream(a1); - buf.stream(a2); - buf.stream(a3); - buf.stream(a4); - buf.stream(a5); - buf.stream(a6); - buf.stream(a7); - buf.stream(a8); + format_private(buf, args...); return buf.to_string(); } -- cgit v1.2.1