Improve support for C++98 compilers that require a copy ctor when binding a reference to a temporary.
This commit is contained in:
parent
dd32508ce6
commit
2d485d1916
@ -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;
|
||||
|
18
format.h
18
format.h
@ -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;
|
||||
@ -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.
|
||||
*/
|
||||
@ -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. */
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user