Add deprecation comments to folly::makeFuture.
[folly.git] / folly / docs / Format.md
index 5696c8be0b28d150201c24d1a8a5e38f12de91d4..b822c21a7591bf96ea27574aea0c56ffea760166 100644 (file)
@@ -63,7 +63,7 @@ std::cout << format("The only {0[what]} is {0[value]}", m);
 // 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);
+std::string result = sformat("The only {0[what]} is {0[value]}", m);
 // => "The only answer is 42"
 
 // {} works for vformat too
@@ -82,6 +82,16 @@ std::cout << vformat("{0} {2} {1}", t);
 std::cout << format("{:X<10} {}", "hello", "world");
 // => "helloXXXXX world"
 
+// Field width may be a runtime value rather than part of the format string
+int x = 6;
+std::cout << format("{:-^*}", x, "hi");
+// => "--hi--"
+
+// Explicit arguments work with dynamic field width, as long as indexes are
+// given for both the value and the field width.
+std::cout << format("{2:+^*0}",
+9, "unused", 456); // => "+++456+++"
+
 // Format supports printf-style format specifiers
 std::cout << format("{0:05d} decimal = {0:04x} hex", 42);
 // => "00042 decimal = 002a hex"
@@ -124,7 +134,7 @@ Format string (`vformat`):
 - `format_spec`: format specification, see below
 
 Format specification:
-`[[fill] align] [sign] ["#"] ["0"] [width] [","] ["." precision] [type]`
+`[[fill] align] [sign] ["#"] ["0"] [width] [","] ["." precision] ["."] [type]`
 
 - `fill` (may only be specified if `align` is also specified): pad with this
   character ('` `' (space) or '`0`' (zero) might be useful; space is default)
@@ -142,13 +152,18 @@ Format specification:
   `0X` for hexadecimal; only valid for integers)
 - '`0`': 0-pad after sign, same as specifying "`0=`" as the `fill` and
   `align` parameters (only valid for numbers)
-- `width`: minimum field width
+- `width`: minimum field width. May be '`*`' to indicate that the field width
+  is given by an argument. Defaults to the next argument (preceding the value
+  to be formatted) but an explicit argument index may be given following the
+  '`*`'. Not supported in `vformat()`.
 - '`,`' (comma): output comma as thousands' separator (only valid for integers,
   and only for decimal output)
 - `precision` (not allowed for integers):
     - for floating point values, number of digits after decimal point ('`f`' or
       '`F`' presentation) or number of significant digits ('`g`' or '`G`')
     - for others, maximum field size (truncate subsequent characters)
+- '`.`' (when used after precision or in lieu of precison): Forces a trailing
+  decimal point to make it clear this is a floating point value.
 - `type`: presentation format, see below
 
 Presentation formats:
@@ -189,4 +204,3 @@ You can extend `format` for your own class by providing a specialization for
 `folly::FormatValue`.  See `folly/Format.h` and `folly/FormatArg.h` for
 details, and the existing specialization for `folly::dynamic` in
 `folly/dynamic-inl.h` for an implementation example.
-