Add shorthand functions to Format.h.
[folly.git] / folly / docs / Format.md
index 2a16a84d5911dc2446e7218fe423bd1483707005..5696c8be0b28d150201c24d1a8a5e38f12de91d4 100644 (file)
@@ -19,7 +19,9 @@ Here are some code samples to get started:
 
 ``` Cpp
 using folly::format;
+using folly::sformat;
 using folly::vformat;
+using folly::svformat;
 
 // Objects produced by format() can be streamed without creating
 // an intermediary string; {} yields the next argument using default
@@ -27,6 +29,10 @@ using folly::vformat;
 std::cout << format("The answers are {} and {}", 23, 42);
 // => "The answers are 23 and 42"
 
+// If you just want the string, though, you're covered.
+std::string result = sformat("The answers are {} and {}", 23, 42);
+// => "The answers are 23 and 42"
+
 // To insert a literal '{' or '}', just double it.
 std::cout << format("{} {{}} {{{}}}", 23, 42);
 // => "23 {} {42}"
@@ -54,6 +60,11 @@ std::cout << vformat("The only {what} is {value}", m);
 // same as
 std::cout << format("The only {0[what]} is {0[value]}", m);
 // => "The only answer is 42"
+// And if you just want the string,
+std::string result = svformat("The only {what} is {value}", m);
+// => "The only answer is 42"
+std::string result = svformat("The only {0[what]} is {0[value]}", m);
+// => "The only answer is 42"
 
 // {} works for vformat too
 std::vector<int> v {42, 23};