From 2d485d1916669b97109f06ace19ac7b2949fbba1 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 10 Dec 2013 08:08:41 -0800 Subject: [PATCH] Improve support for C++98 compilers that require a copy ctor when binding a reference to a temporary. --- README.rst | 3 ++- format.h | 18 ++++++++---------- format_test.cc | 3 ++- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index caa8a54f..b134d84e 100644 --- a/README.rst +++ b/README.rst @@ -98,7 +98,8 @@ with an arbitrary action performed when formatting is complete: // Formats an error message and prints it to std::cerr. fmt::Formatter ReportError(const char *format) { - return Move(fmt::Formatter(format)); + fmt::Formatter f(format); + return f; } ReportError("File not found: {}") << path; diff --git a/format.h b/format.h index 43e146bf..2ac0bdf2 100644 --- a/format.h +++ b/format.h @@ -1121,7 +1121,8 @@ class NoAction { // Formats an error message and prints it to stdout. fmt::Formatter ReportError(const char *format) { - return Move(fmt::Formatter(format)); + fmt::Formatter f(format); + return f; } ReportError("File not found: {}") << path; @@ -1169,12 +1170,6 @@ class Formatter : private Action, public BasicFormatter { } }; -// Removes a const qualifier from a formatter object making it moveable. -template -Formatter &Move(const Formatter &f) { - return const_cast &>(f); -} - /** Fast integer formatter. */ @@ -1248,11 +1243,13 @@ class FormatInt { \endrst */ inline Formatter<> Format(StringRef format) { - return Move(Formatter<>(format)); + Formatter<> f(format); + return f; } inline Formatter Format(WStringRef format) { - return Move(Formatter(format)); + Formatter f(format); + return f; } /** A formatting action that writes formatted output to stdout. */ @@ -1268,7 +1265,8 @@ class Write { // Example: // Print("Elapsed time: {0:.2f} seconds") << 1.23; inline Formatter Print(StringRef format) { - return Move(Formatter(format)); + Formatter f(format); + return f; } } diff --git a/format_test.cc b/format_test.cc index 2597948a..ffcb06f8 100644 --- a/format_test.cc +++ b/format_test.cc @@ -1341,7 +1341,8 @@ struct PrintError { }; fmt::Formatter ReportError(const char *format) { - return Move(fmt::Formatter(format)); + fmt::Formatter f(format); + return f; } TEST(FormatterTest, Examples) {