mirror of
https://github.com/fmtlib/fmt.git
synced 2025-01-28 18:32:46 +00:00
Return Writer instead of std::string in variadic overloads of Format for performance & consistency with non-variadic versions.
This commit is contained in:
parent
bc2cab2efe
commit
71a5b7a126
@ -1434,11 +1434,11 @@ TEST(FormatterTest, Examples) {
|
|||||||
std::string path = "somefile";
|
std::string path = "somefile";
|
||||||
ReportError("File not found: {0}") << path;
|
ReportError("File not found: {0}") << path;
|
||||||
|
|
||||||
#if FMT_USE_VARIADIC_TEMPLATES
|
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
|
||||||
EXPECT_THROW_MSG(
|
EXPECT_THROW_MSG(
|
||||||
Format("The answer is {:d}", "forty-two"), FormatError,
|
Format("The answer is {:d}", "forty-two"), FormatError,
|
||||||
"unknown format code 'd' for string");
|
"unknown format code 'd' for string");
|
||||||
EXPECT_EQ(L"Cyrillic letter ю", Format(L"Cyrillic letter {}", L'ю'));
|
EXPECT_EQ(L"Cyrillic letter ю", str(Format(L"Cyrillic letter {}", L'ю')));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1501,10 +1501,10 @@ TEST(StrTest, Convert) {
|
|||||||
EXPECT_EQ("2012-12-9", s);
|
EXPECT_EQ("2012-12-9", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FMT_USE_VARIADIC_TEMPLATES
|
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
|
||||||
TEST(FormatTest, Variadic) {
|
TEST(FormatTest, Variadic) {
|
||||||
EXPECT_EQ("Hello, world!1", Format("Hello, {}!{}", "world", 1));
|
EXPECT_EQ("Hello, world!1", str(Format("Hello, {}!{}", "world", 1)));
|
||||||
EXPECT_EQ(L"Hello, world!1", Format(L"Hello, {}!{}", L"world", 1));
|
EXPECT_EQ(L"Hello, world!1", str(Format(L"Hello, {}!{}", L"world", 1)));
|
||||||
}
|
}
|
||||||
#endif // FMT_USE_VARIADIC_TEMPLATES
|
#endif // FMT_USE_VARIADIC_TEMPLATES
|
||||||
|
|
||||||
|
13
format.h
13
format.h
@ -1571,22 +1571,21 @@ inline Formatter<ColorWriter> PrintColored(Color c, StringRef format) {
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FMT_USE_VARIADIC_TEMPLATES
|
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
inline std::string Format(const StringRef &format, const Args & ... args) {
|
inline Writer Format(const StringRef &format, const Args & ... args) {
|
||||||
Writer w;
|
Writer w;
|
||||||
w.Format(format, args...);
|
w.Format(format, args...);
|
||||||
return str(w);
|
return std::move(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
inline std::wstring Format(const WStringRef &format, const Args & ... args) {
|
inline WWriter Format(const WStringRef &format, const Args & ... args) {
|
||||||
WWriter w;
|
WWriter w;
|
||||||
w.Format(format, args...);
|
w.Format(format, args...);
|
||||||
return str(w);
|
return std::move(w);
|
||||||
}
|
}
|
||||||
#endif // FMT_USE_VARIADIC_TEMPLATES
|
#endif // FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore warnings.
|
// Restore warnings.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user