From Jason Turner

[fs.class.path]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp0zfuj_dm/{from.md → to.md} +119 -32
tmp/tmp0zfuj_dm/{from.md → to.md} RENAMED
@@ -36,12 +36,12 @@ Pathnames are formatted according to the generic pathname format grammar
36
 
37
  *Pathname resolution* is the operating system dependent mechanism for
38
  resolving a pathname to a particular file in a file hierarchy. There may
39
  be multiple pathnames that resolve to the same file.
40
 
41
- [*Example 1*: POSIX specifies the mechanism in section 4.12, Pathname
42
- resolution. — *end example*]
43
 
44
  ``` cpp
45
  namespace std::filesystem {
46
  class path {
47
  public:
@@ -124,22 +124,24 @@ namespace std::filesystem {
124
 
125
  template<class EcharT, class traits = char_traits<EcharT>,
126
  class Allocator = allocator<EcharT>>
127
  basic_string<EcharT, traits, Allocator>
128
  string(const Allocator& a = Allocator()) const;
129
- std::string string() const;
 
130
  std::wstring wstring() const;
131
  std::u8string u8string() const;
132
  std::u16string u16string() const;
133
  std::u32string u32string() const;
134
 
135
  // [fs.path.generic.obs], generic format observers
136
  template<class EcharT, class traits = char_traits<EcharT>,
137
  class Allocator = allocator<EcharT>>
138
  basic_string<EcharT, traits, Allocator>
139
  generic_string(const Allocator& a = Allocator()) const;
140
- std::string generic_string() const;
 
141
  std::wstring generic_wstring() const;
142
  std::u8string generic_u8string() const;
143
  std::u16string generic_u16string() const;
144
  std::u32string generic_u32string() const;
145
 
@@ -158,11 +160,11 @@ namespace std::filesystem {
158
  path filename() const;
159
  path stem() const;
160
  path extension() const;
161
 
162
  // [fs.path.query], query
163
- [[nodiscard]] bool empty() const noexcept;
164
  bool has_root_name() const;
165
  bool has_root_directory() const;
166
  bool has_root_path() const;
167
  bool has_relative_path() const;
168
  bool has_parent_path() const;
@@ -352,12 +354,12 @@ generic format and is not acceptable to the operating system as a native
352
  path.
353
 
354
  [*Note 2*: Some operating systems have no unambiguous way to
355
  distinguish between native format and generic format arguments. This is
356
  by design as it simplifies use for operating systems that do not require
357
- disambiguation. An implementation for an operating system where
358
- disambiguation is required is permitted to distinguish between the
359
  formats. — *end note*]
360
 
361
  Pathnames are converted as needed between the generic and native formats
362
  in an operating-system-dependent manner. Let *G(n)* and *N(g)* in a
363
  mathematical sense be the implementation’s functions that convert
@@ -443,16 +445,16 @@ named `Source` shall be one of:
443
  \[`source.begin()`, `source.end()`).
444
  - `basic_string_view<EcharT, traits>`. A function argument
445
  `const Source&` `source` shall have an effective range
446
  \[`source.begin()`, `source.end()`).
447
  - A type meeting the *Cpp17InputIterator* requirements that iterates
448
- over a NTCTS. The value type shall be an encoded character type. A
449
  function argument `const Source&` `source` shall have an effective
450
  range \[`source`, `end`) where `end` is the first iterator value with
451
  an element value equal to `iterator_traits<Source>::value_type()`.
452
  - A character array that after array-to-pointer decay results in a
453
- pointer to the start of a NTCTS. The value type shall be an encoded
454
  character type. A function argument `const Source&` `source` shall
455
  have an effective range \[`source`, `end`) where `end` is the first
456
  iterator value with an element value equal to
457
  `iterator_traits<decay_t<Source>>::value_type()`.
458
 
@@ -478,11 +480,11 @@ Arguments of type `Source` shall not be null pointers.
478
 
479
  ``` cpp
480
  path() noexcept;
481
  ```
482
 
483
- *Ensures:* `empty() == true`.
484
 
485
  ``` cpp
486
  path(const path& p);
487
  path(path&& p) noexcept;
488
  ```
@@ -726,11 +728,11 @@ template<class InputIterator>
726
 
727
  ``` cpp
728
  void clear() noexcept;
729
  ```
730
 
731
- *Ensures:* `empty() == true`.
732
 
733
  ``` cpp
734
  path& make_preferred();
735
  ```
736
 
@@ -855,24 +857,22 @@ operator string_type() const;
855
  ```
856
 
857
  *Returns:* `native()`.
858
 
859
  ``` cpp
860
- template<class EcharT, class traits = char_traits<EcharT>,
861
- class Allocator = allocator<EcharT>>
862
- basic_string<EcharT, traits, Allocator>
863
- string(const Allocator& a = Allocator()) const;
864
  ```
865
 
866
  *Returns:* `native()`.
867
 
868
  *Remarks:* All memory allocation, including for the return value, shall
869
  be performed by `a`. Conversion, if any, is specified by
870
  [[fs.path.cvt]].
871
 
872
  ``` cpp
873
- std::string string() const;
874
  std::wstring wstring() const;
875
  std::u8string u8string() const;
876
  std::u16string u16string() const;
877
  std::u32string u32string() const;
878
  ```
@@ -880,10 +880,20 @@ std::u32string u32string() const;
880
  *Returns:* `native()`.
881
 
882
  *Remarks:* Conversion, if any, is performed as specified by
883
  [[fs.path.cvt]].
884
 
 
 
 
 
 
 
 
 
 
 
885
  ##### Generic format observers <a id="fs.path.generic.obs">[[fs.path.generic.obs]]</a>
886
 
887
  Generic format observer functions return strings formatted according to
888
  the generic pathname format [[fs.path.generic]]. A single slash (`'/'`)
889
  character is used as the *directory-separator*.
@@ -899,34 +909,42 @@ path("foo\\bar").generic_string()
899
  returns `"foo/bar"`.
900
 
901
  — *end example*]
902
 
903
  ``` cpp
904
- template<class EcharT, class traits = char_traits<EcharT>,
905
- class Allocator = allocator<EcharT>>
906
- basic_string<EcharT, traits, Allocator>
907
- generic_string(const Allocator& a = Allocator()) const;
908
  ```
909
 
910
  *Returns:* The pathname in the generic format.
911
 
912
  *Remarks:* All memory allocation, including for the return value, shall
913
  be performed by `a`. Conversion, if any, is specified by
914
  [[fs.path.cvt]].
915
 
916
  ``` cpp
917
- std::string generic_string() const;
918
  std::wstring generic_wstring() const;
919
  std::u8string generic_u8string() const;
920
  std::u16string generic_u16string() const;
921
  std::u32string generic_u32string() const;
922
  ```
923
 
924
  *Returns:* The pathname in the generic format.
925
 
926
  *Remarks:* Conversion, if any, is specified by  [[fs.path.cvt]].
927
 
 
 
 
 
 
 
 
 
 
 
928
  ##### Compare <a id="fs.path.compare">[[fs.path.compare]]</a>
929
 
930
  ``` cpp
931
  int compare(const path& p) const noexcept;
932
  ```
@@ -1057,22 +1075,22 @@ path(".bar").extension(); // yields "" and stem() is ".bar"
1057
  path("..bar").extension(); // yields ".bar" and stem() is "."
1058
  ```
1059
 
1060
  — *end example*]
1061
 
1062
- [*Note 3*: The period is included in the return value so that it is
1063
  possible to distinguish between no extension and an empty
1064
  extension. — *end note*]
1065
 
1066
- [*Note 4*: On non-POSIX operating systems, for a path `p`, it is
1067
  possible that `p.stem() + p.extension() == p.filename()` is `false`,
1068
  even though the generic format pathnames are the same. — *end note*]
1069
 
1070
  ##### Query <a id="fs.path.query">[[fs.path.query]]</a>
1071
 
1072
  ``` cpp
1073
- [[nodiscard]] bool empty() const noexcept;
1074
  ```
1075
 
1076
  *Returns:* `true` if the pathname in the generic format is empty,
1077
  otherwise `false`.
1078
 
@@ -1176,11 +1194,11 @@ path lexically_relative(const path& base) const;
1176
  - any *filename* in `relative_path()` or `base.relative_path()` can be
1177
  interpreted as a *root-name*,
1178
 
1179
  returns `path()`.
1180
 
1181
- [*Note 5*: On a POSIX implementation, no *filename* in a
1182
  *relative-path* is acceptable as a *root-name*. — *end note*]
1183
 
1184
  Determines the first mismatched element of `*this` and `base` as if by:
1185
 
1186
  ``` cpp
@@ -1219,28 +1237,28 @@ The above assertions will succeed. On Windows, the returned path’s
1219
  *directory-separator* characters will be backslashes rather than
1220
  slashes, but that does not affect `path` equality.
1221
 
1222
  — *end example*]
1223
 
1224
- [*Note 6*: If symlink following semantics are desired, use the
1225
  operational function `relative()`. — *end note*]
1226
 
1227
- [*Note 7*: If normalization [[fs.path.generic]] is needed to ensure
1228
  consistent matching of elements, apply `lexically_normal()` to `*this`,
1229
  `base`, or both. — *end note*]
1230
 
1231
  ``` cpp
1232
  path lexically_proximate(const path& base) const;
1233
  ```
1234
 
1235
  *Returns:* If the value of `lexically_relative(base)` is not an empty
1236
  path, return it. Otherwise return `*this`.
1237
 
1238
- [*Note 8*: If symlink following semantics are desired, use the
1239
  operational function `proximate()`. — *end note*]
1240
 
1241
- [*Note 9*: If normalization [[fs.path.generic]] is needed to ensure
1242
  consistent matching of elements, apply `lexically_normal()` to `*this`,
1243
  `base`, or both. — *end note*]
1244
 
1245
  #### Iterators <a id="fs.path.itr">[[fs.path.itr]]</a>
1246
 
@@ -1258,13 +1276,13 @@ iterators referring to elements of that object.
1258
 
1259
  For the elements of the pathname in the generic format, the forward
1260
  traversal order is as follows:
1261
 
1262
  - The *root-name* element, if present.
1263
- - The *root-directory* element, if present. \[*Note 1*: The generic
1264
- format is required to ensure lexicographical comparison works
1265
- correctly. — *end note*]
1266
  - Each successive *filename* element, if present.
1267
  - An empty element, if a trailing non-root *directory-separator* is
1268
  present.
1269
 
1270
  The backward traversal order is the reverse of forward traversal.
@@ -1359,10 +1377,79 @@ friend strong_ordering operator<=>(const path& lhs, const path& rhs) noexcept;
1359
  friend path operator/(const path& lhs, const path& rhs);
1360
  ```
1361
 
1362
  *Effects:* Equivalent to: `return path(lhs) /= rhs;`
1363
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1364
  #### Hash support <a id="fs.path.hash">[[fs.path.hash]]</a>
1365
 
1366
  ``` cpp
1367
  template<> struct hash<filesystem::path>;
1368
  ```
 
36
 
37
  *Pathname resolution* is the operating system dependent mechanism for
38
  resolving a pathname to a particular file in a file hierarchy. There may
39
  be multiple pathnames that resolve to the same file.
40
 
41
+ [*Example 1*: For POSIX-based operating systems, this mechanism is
42
+ specified in POSIX, section 4.12, Pathname resolution. — *end example*]
43
 
44
  ``` cpp
45
  namespace std::filesystem {
46
  class path {
47
  public:
 
124
 
125
  template<class EcharT, class traits = char_traits<EcharT>,
126
  class Allocator = allocator<EcharT>>
127
  basic_string<EcharT, traits, Allocator>
128
  string(const Allocator& a = Allocator()) const;
129
+ std::string display_string() const;
130
+ std::string system_encoded_string() const;
131
  std::wstring wstring() const;
132
  std::u8string u8string() const;
133
  std::u16string u16string() const;
134
  std::u32string u32string() const;
135
 
136
  // [fs.path.generic.obs], generic format observers
137
  template<class EcharT, class traits = char_traits<EcharT>,
138
  class Allocator = allocator<EcharT>>
139
  basic_string<EcharT, traits, Allocator>
140
  generic_string(const Allocator& a = Allocator()) const;
141
+ std::string generic_display_string() const;
142
+ std::string generic_system_encoded_string() const;
143
  std::wstring generic_wstring() const;
144
  std::u8string generic_u8string() const;
145
  std::u16string generic_u16string() const;
146
  std::u32string generic_u32string() const;
147
 
 
160
  path filename() const;
161
  path stem() const;
162
  path extension() const;
163
 
164
  // [fs.path.query], query
165
+ bool empty() const noexcept;
166
  bool has_root_name() const;
167
  bool has_root_directory() const;
168
  bool has_root_path() const;
169
  bool has_relative_path() const;
170
  bool has_parent_path() const;
 
354
  path.
355
 
356
  [*Note 2*: Some operating systems have no unambiguous way to
357
  distinguish between native format and generic format arguments. This is
358
  by design as it simplifies use for operating systems that do not require
359
+ disambiguation. It is possible that an implementation for an operating
360
+ system where disambiguation is needed distinguishes between the
361
  formats. — *end note*]
362
 
363
  Pathnames are converted as needed between the generic and native formats
364
  in an operating-system-dependent manner. Let *G(n)* and *N(g)* in a
365
  mathematical sense be the implementation’s functions that convert
 
445
  \[`source.begin()`, `source.end()`).
446
  - `basic_string_view<EcharT, traits>`. A function argument
447
  `const Source&` `source` shall have an effective range
448
  \[`source.begin()`, `source.end()`).
449
  - A type meeting the *Cpp17InputIterator* requirements that iterates
450
+ over an NTCTS. The value type shall be an encoded character type. A
451
  function argument `const Source&` `source` shall have an effective
452
  range \[`source`, `end`) where `end` is the first iterator value with
453
  an element value equal to `iterator_traits<Source>::value_type()`.
454
  - A character array that after array-to-pointer decay results in a
455
+ pointer to the start of an NTCTS. The value type shall be an encoded
456
  character type. A function argument `const Source&` `source` shall
457
  have an effective range \[`source`, `end`) where `end` is the first
458
  iterator value with an element value equal to
459
  `iterator_traits<decay_t<Source>>::value_type()`.
460
 
 
480
 
481
  ``` cpp
482
  path() noexcept;
483
  ```
484
 
485
+ *Ensures:* `empty()` is `true`.
486
 
487
  ``` cpp
488
  path(const path& p);
489
  path(path&& p) noexcept;
490
  ```
 
728
 
729
  ``` cpp
730
  void clear() noexcept;
731
  ```
732
 
733
+ *Ensures:* `empty()` is `true`.
734
 
735
  ``` cpp
736
  path& make_preferred();
737
  ```
738
 
 
857
  ```
858
 
859
  *Returns:* `native()`.
860
 
861
  ``` cpp
862
+ template<class EcharT, class traits = char_traits<EcharT>, class Allocator = allocator<EcharT>>
863
+ basic_string<EcharT, traits, Allocator> string(const Allocator& a = Allocator()) const;
 
 
864
  ```
865
 
866
  *Returns:* `native()`.
867
 
868
  *Remarks:* All memory allocation, including for the return value, shall
869
  be performed by `a`. Conversion, if any, is specified by
870
  [[fs.path.cvt]].
871
 
872
  ``` cpp
873
+ std::string system_encoded_string() const;
874
  std::wstring wstring() const;
875
  std::u8string u8string() const;
876
  std::u16string u16string() const;
877
  std::u32string u32string() const;
878
  ```
 
880
  *Returns:* `native()`.
881
 
882
  *Remarks:* Conversion, if any, is performed as specified by
883
  [[fs.path.cvt]].
884
 
885
+ ``` cpp
886
+ std::string display_string() const;
887
+ ```
888
+
889
+ *Returns:* `std::format("{}", *this)`.
890
+
891
+ [*Note 3*: The returned string is suitable for use with
892
+ formatting [[format.functions]] and print
893
+ functions [[print.fun]]. — *end note*]
894
+
895
  ##### Generic format observers <a id="fs.path.generic.obs">[[fs.path.generic.obs]]</a>
896
 
897
  Generic format observer functions return strings formatted according to
898
  the generic pathname format [[fs.path.generic]]. A single slash (`'/'`)
899
  character is used as the *directory-separator*.
 
909
  returns `"foo/bar"`.
910
 
911
  — *end example*]
912
 
913
  ``` cpp
914
+ template<class EcharT, class traits = char_traits<EcharT>, class Allocator = allocator<EcharT>>
915
+ basic_string<EcharT, traits, Allocator> generic_string(const Allocator& a = Allocator()) const;
 
 
916
  ```
917
 
918
  *Returns:* The pathname in the generic format.
919
 
920
  *Remarks:* All memory allocation, including for the return value, shall
921
  be performed by `a`. Conversion, if any, is specified by
922
  [[fs.path.cvt]].
923
 
924
  ``` cpp
925
+ std::string generic_system_encoded_string() const;
926
  std::wstring generic_wstring() const;
927
  std::u8string generic_u8string() const;
928
  std::u16string generic_u16string() const;
929
  std::u32string generic_u32string() const;
930
  ```
931
 
932
  *Returns:* The pathname in the generic format.
933
 
934
  *Remarks:* Conversion, if any, is specified by  [[fs.path.cvt]].
935
 
936
+ ``` cpp
937
+ std::string generic_display_string() const;
938
+ ```
939
+
940
+ *Returns:* `std::format("{:g}", *this)`.
941
+
942
+ [*Note 4*: The returned string is suitable for use with
943
+ formatting [[format.functions]] and print
944
+ functions [[print.fun]]. — *end note*]
945
+
946
  ##### Compare <a id="fs.path.compare">[[fs.path.compare]]</a>
947
 
948
  ``` cpp
949
  int compare(const path& p) const noexcept;
950
  ```
 
1075
  path("..bar").extension(); // yields ".bar" and stem() is "."
1076
  ```
1077
 
1078
  — *end example*]
1079
 
1080
+ [*Note 5*: The period is included in the return value so that it is
1081
  possible to distinguish between no extension and an empty
1082
  extension. — *end note*]
1083
 
1084
+ [*Note 6*: On non-POSIX operating systems, for a path `p`, it is
1085
  possible that `p.stem() + p.extension() == p.filename()` is `false`,
1086
  even though the generic format pathnames are the same. — *end note*]
1087
 
1088
  ##### Query <a id="fs.path.query">[[fs.path.query]]</a>
1089
 
1090
  ``` cpp
1091
+ bool empty() const noexcept;
1092
  ```
1093
 
1094
  *Returns:* `true` if the pathname in the generic format is empty,
1095
  otherwise `false`.
1096
 
 
1194
  - any *filename* in `relative_path()` or `base.relative_path()` can be
1195
  interpreted as a *root-name*,
1196
 
1197
  returns `path()`.
1198
 
1199
+ [*Note 7*: On a POSIX implementation, no *filename* in a
1200
  *relative-path* is acceptable as a *root-name*. — *end note*]
1201
 
1202
  Determines the first mismatched element of `*this` and `base` as if by:
1203
 
1204
  ``` cpp
 
1237
  *directory-separator* characters will be backslashes rather than
1238
  slashes, but that does not affect `path` equality.
1239
 
1240
  — *end example*]
1241
 
1242
+ [*Note 8*: If symlink following semantics are desired, use the
1243
  operational function `relative()`. — *end note*]
1244
 
1245
+ [*Note 9*: If normalization [[fs.path.generic]] is needed to ensure
1246
  consistent matching of elements, apply `lexically_normal()` to `*this`,
1247
  `base`, or both. — *end note*]
1248
 
1249
  ``` cpp
1250
  path lexically_proximate(const path& base) const;
1251
  ```
1252
 
1253
  *Returns:* If the value of `lexically_relative(base)` is not an empty
1254
  path, return it. Otherwise return `*this`.
1255
 
1256
+ [*Note 10*: If symlink following semantics are desired, use the
1257
  operational function `proximate()`. — *end note*]
1258
 
1259
+ [*Note 11*: If normalization [[fs.path.generic]] is needed to ensure
1260
  consistent matching of elements, apply `lexically_normal()` to `*this`,
1261
  `base`, or both. — *end note*]
1262
 
1263
  #### Iterators <a id="fs.path.itr">[[fs.path.itr]]</a>
1264
 
 
1276
 
1277
  For the elements of the pathname in the generic format, the forward
1278
  traversal order is as follows:
1279
 
1280
  - The *root-name* element, if present.
1281
+ - The *root-directory* element, if present. \[*Note 1*: It is possible
1282
+ that the use of the generic format is needed to ensure correct
1283
+ lexicographical comparison. — *end note*]
1284
  - Each successive *filename* element, if present.
1285
  - An empty element, if a trailing non-root *directory-separator* is
1286
  present.
1287
 
1288
  The backward traversal order is the reverse of forward traversal.
 
1377
  friend path operator/(const path& lhs, const path& rhs);
1378
  ```
1379
 
1380
  *Effects:* Equivalent to: `return path(lhs) /= rhs;`
1381
 
1382
+ #### Formatting support <a id="fs.path.fmtr">[[fs.path.fmtr]]</a>
1383
+
1384
+ ##### Formatting support overview <a id="fs.path.fmtr.general">[[fs.path.fmtr.general]]</a>
1385
+
1386
+ ``` cpp
1387
+ namespace std {
1388
+ template<class charT> struct formatter<filesystem::path, charT> {
1389
+ constexpr void set_debug_format();
1390
+
1391
+ constexpr typename basic_format_parse_context<charT>::iterator
1392
+ parse(basic_format_parse_context<charT>& ctx);
1393
+
1394
+ template<class FormatContext>
1395
+ typename FormatContext::iterator
1396
+ format(const filesystem::path& path, FormatContext& ctx) const;
1397
+ };
1398
+ }
1399
+ ```
1400
+
1401
+ ##### Formatting support functions <a id="fs.path.fmtr.funcs">[[fs.path.fmtr.funcs]]</a>
1402
+
1403
+ Formatting of paths uses formatting specifiers of the form
1404
+
1405
+ ``` bnf
1406
+ path-format-spec:
1407
+ fill-and-alignₒₚₜ widthₒₚₜ '?'ₒₚₜ 'g'ₒₚₜ
1408
+ ```
1409
+
1410
+ where the productions *fill-and-align* and *width* are described in
1411
+ [[format.string]]. If the `?` option is used then the path is formatted
1412
+ as an escaped string [[format.string.escaped]].
1413
+
1414
+ ``` cpp
1415
+ constexpr void set_debug_format();
1416
+ ```
1417
+
1418
+ *Effects:* Modifies the state of the `formatter` to be as if the
1419
+ *path-format-spec* parsed by the last call to `parse` contained the `?`
1420
+ option.
1421
+
1422
+ ``` cpp
1423
+ constexpr typename basic_format_parse_context<charT>::iterator
1424
+ parse(basic_format_parse_context<charT>& ctx);
1425
+ ```
1426
+
1427
+ *Effects:* Parses the format specifier as a *path-format-spec* and
1428
+ stores the parsed specifiers in `*this`.
1429
+
1430
+ *Returns:* An iterator past the end of the *path-format-spec*.
1431
+
1432
+ ``` cpp
1433
+ template<class FormatContext>
1434
+ typename FormatContext::iterator
1435
+ format(const filesystem::path& p, FormatContext& ctx) const;
1436
+ ```
1437
+
1438
+ *Effects:* Let `s` be `p.generic_string<filesystem::path::value_type>()`
1439
+ if the `g` option is used, otherwise `p.native()`. Writes `s` into
1440
+ `ctx.out()`, adjusted according to the *path-format-spec*. If `charT` is
1441
+ `char`, `path::value_type` is `wchar_t`, and the literal encoding is
1442
+ UTF-8, then the escaped path is transcoded from the native encoding for
1443
+ wide character strings to UTF-8 with maximal subparts of ill-formed
1444
+ subsequences substituted with ‘U+fffd‘ replacement character per the
1445
+ Unicode Standard, Chapter 3.9 ‘U+fffd‘ Substitution in Conversion. If
1446
+ `charT` and `path::value_type` are the same then no transcoding is
1447
+ performed. Otherwise, transcoding is *implementation-defined*.
1448
+
1449
+ *Returns:* An iterator past the end of the output range.
1450
+
1451
  #### Hash support <a id="fs.path.hash">[[fs.path.hash]]</a>
1452
 
1453
  ``` cpp
1454
  template<> struct hash<filesystem::path>;
1455
  ```