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) {