Skip to content

Commit

Permalink
Improve support for C++98 compilers that require a copy ctor when bin…
Browse files Browse the repository at this point in the history
…ding a reference to a temporary.
  • Loading branch information
vitaut committed Dec 10, 2013
1 parent dd32508 commit 2d485d1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrintError> ReportError(const char *format) {
return Move(fmt::Formatter<PrintError>(format));
fmt::Formatter<PrintError> f(format);
return f;
}
ReportError("File not found: {}") << path;
Expand Down
18 changes: 8 additions & 10 deletions format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,8 @@ class NoAction {
// Formats an error message and prints it to stdout.
fmt::Formatter<PrintError> ReportError(const char *format) {
return Move(fmt::Formatter<PrintError>(format));
fmt::Formatter f<PrintError>(format);
return f;
}
ReportError("File not found: {}") << path;
Expand Down Expand Up @@ -1169,12 +1170,6 @@ class Formatter : private Action, public BasicFormatter<Char> {
}
};

// Removes a const qualifier from a formatter object making it moveable.
template <typename Action, typename Char>
Formatter<Action, Char> &Move(const Formatter<Action, Char> &f) {
return const_cast<Formatter<Action, Char> &>(f);
}

/**
Fast integer formatter.
*/
Expand Down Expand Up @@ -1248,11 +1243,13 @@ class FormatInt {
\endrst
*/
inline Formatter<> Format(StringRef format) {
return Move(Formatter<>(format));
Formatter<> f(format);
return f;
}

inline Formatter<NoAction, wchar_t> Format(WStringRef format) {
return Move(Formatter<NoAction, wchar_t>(format));
Formatter<NoAction, wchar_t> f(format);
return f;
}

/** A formatting action that writes formatted output to stdout. */
Expand All @@ -1268,7 +1265,8 @@ class Write {
// Example:
// Print("Elapsed time: {0:.2f} seconds") << 1.23;
inline Formatter<Write> Print(StringRef format) {
return Move(Formatter<Write>(format));
Formatter<Write> f(format);
return f;
}
}

Expand Down
3 changes: 2 additions & 1 deletion format_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,8 @@ struct PrintError {
};

fmt::Formatter<PrintError> ReportError(const char *format) {
return Move(fmt::Formatter<PrintError>(format));
fmt::Formatter<PrintError> f(format);
return f;
}

TEST(FormatterTest, Examples) {
Expand Down

0 comments on commit 2d485d1

Please sign in to comment.