From fe0a6b7c674a59c4f242de431851a255b3246a85 Mon Sep 17 00:00:00 2001 From: Jin S Date: Fri, 22 Mar 2024 11:23:50 -0400 Subject: [PATCH] examples --- doc/syntax.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/syntax.rst b/doc/syntax.rst index 563d6f330465..ad0facd70c45 100644 --- a/doc/syntax.rst +++ b/doc/syntax.rst @@ -493,7 +493,7 @@ Format specifications for range types have the following syntax: .. productionlist:: sf range_format_spec: [":" [`n`][`range_type`][`range_underlying_spec`]] -The `n` option causes the range to be formatted without the opening and closing brackets. +The `n` option formats the range without the opening and closing brackets. The available presentation types for `range_type` are: @@ -509,7 +509,8 @@ The available presentation types for `range_type` are: | | | +---------+----------------------------------------------------------+ -If `range_type` is `s` or `?s`, the underlying type of the range must be a char type. +If `range_type` is `s` or `?s`, the underlying type of the range must be a character type. The +`n` option and `range_underlying_spec` are mutually exclusive with `s` and `?s`. The `underlying_spec` is parsed based on the formatter of the range's reference type. @@ -526,6 +527,12 @@ Examples:: // Result: [0xa, 0x14, 0x1e] fmt::format("{}", vector{'h', 'e', 'l', 'l', 'o'}); // Result: ['h', 'e', 'l', 'l', 'o'] + fmt::format("{:n}", vector{'h', 'e', 'l', 'l', 'o'}); + // Result: 'h', 'e', 'l', 'l', 'o' + fmt::format("{:s}", vector{'h', 'e', 'l', 'l', 'o'}); + // Result: "hello" + fmt::format("{:?s}", vector{'h', 'e', 'l', 'l', 'o', '\n'}); + // Result: "hello\n" fmt::format("{::}", vector{'h', 'e', 'l', 'l', 'o'}); // Result: [h, e, l, l, o] fmt::format("{::d}", vector{'h', 'e', 'l', 'l', 'o'});