Commit 3d9b0f07 authored by Victor Zverovich's avatar Victor Zverovich

Add ArgInserter::str().

parent 1b3c197b
...@@ -380,6 +380,8 @@ class ArgInserter { ...@@ -380,6 +380,8 @@ class ArgInserter {
return Proxy(f); return Proxy(f);
} }
std::string str() const { return Format()->str(); }
// Performs formatting and returns a C string with the output. // Performs formatting and returns a C string with the output.
friend const char *c_str(Proxy p) { friend const char *c_str(Proxy p) {
return Format(p)->c_str(); return Format(p)->c_str();
......
...@@ -789,6 +789,17 @@ TEST(TempFormatterTest, Example) { ...@@ -789,6 +789,17 @@ TEST(TempFormatterTest, Example) {
ReportError("File not found: {0}") << path; ReportError("File not found: {0}") << path;
} }
template <typename T>
std::string str(const T &value) {
return (fmt::Format("{0}") << value).str();
}
TEST(StrTest, Convert) {
EXPECT_EQ("42", str(42));
std::string s = str(Date(2012, 12, 9));
EXPECT_EQ("2012-12-9", s);
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
#ifdef _WIN32 #ifdef _WIN32
// Disable message boxes on assertion failures. // Disable message boxes on assertion failures.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment