Return Writer instead of std::string in variadic overloads of Format for performance & consistency with non-variadic versions.

This commit is contained in:
Victor Zverovich 2014-04-24 07:32:01 -07:00
parent bc2cab2efe
commit 71a5b7a126
2 changed files with 11 additions and 12 deletions

View File

@ -1434,11 +1434,11 @@ TEST(FormatterTest, Examples) {
std::string path = "somefile";
ReportError("File not found: {0}") << path;
#if FMT_USE_VARIADIC_TEMPLATES
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
EXPECT_THROW_MSG(
Format("The answer is {:d}", "forty-two"), FormatError,
"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
}
@ -1501,10 +1501,10 @@ TEST(StrTest, Convert) {
EXPECT_EQ("2012-12-9", s);
}
#if FMT_USE_VARIADIC_TEMPLATES
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
TEST(FormatTest, Variadic) {
EXPECT_EQ("Hello, world!1", Format("Hello, {}!{}", "world", 1));
EXPECT_EQ(L"Hello, world!1", Format(L"Hello, {}!{}", L"world", 1));
EXPECT_EQ("Hello, world!1", str(Format("Hello, {}!{}", "world", 1)));
EXPECT_EQ(L"Hello, world!1", str(Format(L"Hello, {}!{}", L"world", 1)));
}
#endif // FMT_USE_VARIADIC_TEMPLATES

View File

@ -1571,22 +1571,21 @@ inline Formatter<ColorWriter> PrintColored(Color c, StringRef format) {
return f;
}
#if FMT_USE_VARIADIC_TEMPLATES
#if FMT_USE_VARIADIC_TEMPLATES && FMT_USE_RVALUE_REFERENCES
template<typename... Args>
inline std::string Format(const StringRef &format, const Args & ... args) {
inline Writer Format(const StringRef &format, const Args & ... args) {
Writer w;
w.Format(format, args...);
return str(w);
return std::move(w);
}
template<typename... Args>
inline std::wstring Format(const WStringRef &format, const Args & ... args) {
inline WWriter Format(const WStringRef &format, const Args & ... args) {
WWriter w;
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.