Files
cppdraft_translate/cppdraft/fs/path/construct.md
2025-10-25 03:02:53 +03:00

140 lines
5.3 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[fs.path.construct]
# 31 Input/output library [[input.output]](./#input.output)
## 31.12 File systems [[filesystems]](filesystems#fs.path.construct)
### 31.12.6 Class path [[fs.class.path]](fs.class.path#fs.path.construct)
#### 31.12.6.5 Members [[fs.path.member]](fs.path.member#fs.path.construct)
#### 31.12.6.5.1 Constructors [fs.path.construct]
[🔗](#lib:path,constructor)
`path() noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14134)
*Postconditions*: empty() is true[.](#1.sentence-1)
[🔗](#lib:path,constructor_)
`path(const path& p);
path(path&& p) noexcept;
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14146)
*Effects*: Constructs an object of class path having the same pathname in the native and generic formats, respectively,
as the original value of p[.](#2.sentence-1)
In the second form, p is left in a valid but unspecified state[.](#2.sentence-2)
[🔗](#lib:path,constructor__)
`path(string_type&& source, format fmt = auto_format);
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14160)
*Effects*: Constructs an object of class path for which the pathname in the detected-format of source has the original value of source ([[fs.path.fmt.cvt]](fs.path.fmt.cvt "31.12.6.3.1Argument format conversions")),
converting format if required ([[fs.path.fmt.cvt]](fs.path.fmt.cvt "31.12.6.3.1Argument format conversions"))[.](#3.sentence-1)
source is left in a valid but unspecified state[.](#3.sentence-2)
[🔗](#lib:path,constructor___)
`template<class Source>
path(const Source& source, format fmt = auto_format);
template<class InputIterator>
path(InputIterator first, InputIterator last, format fmt = auto_format);
`
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14178)
*Effects*: Let s be the effective range of source ([[fs.path.req]](fs.path.req "31.12.6.4Requirements"))
or the range [first, last), with the encoding converted if required ([[fs.path.cvt]](fs.path.cvt "31.12.6.3Conversions"))[.](#4.sentence-1)
Finds the detected-format of s ([[fs.path.fmt.cvt]](fs.path.fmt.cvt "31.12.6.3.1Argument format conversions"))
and constructs an object of class path for which the pathname in that format is s[.](#4.sentence-2)
[🔗](#lib:path,constructor____)
`template<class Source>
path(const Source& source, const locale& loc, format fmt = auto_format);
template<class InputIterator>
path(InputIterator first, InputIterator last, const locale& loc, format fmt = auto_format);
`
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14196)
*Mandates*: The value type of Source and InputIterator ischar[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14201)
*Effects*: Let s be the effective range of source or the range [first, last),
after converting the encoding as
follows:
- [(6.1)](#6.1)
If value_type is wchar_t, converts to the native
wide encoding ([[fs.path.type.cvt]](fs.path.type.cvt "31.12.6.3.2Type and encoding conversions")) using the codecvt<wchar_t, char, mbstate_t> facet of loc[.](#6.1.sentence-1)
- [(6.2)](#6.2)
Otherwise a conversion is performed using thecodecvt<wchar_t, char, mbstate_t> facet of loc, and then a second
conversion to the current ordinary encoding[.](#6.2.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L14218)
Finds the detected-format of s ([[fs.path.fmt.cvt]](fs.path.fmt.cvt "31.12.6.3.1Argument format conversions"))
and constructs an object of class path for which the pathname in that format is s[.](#7.sentence-1)
[*Example [1](#example-1)*:
A string is to be read from a database
that is encoded in ISO/IEC 8859-1, and used to create a directory:namespace fs = std::filesystem;
std::string latin1_string = read_latin1_data();
codecvt_8859_1<wchar_t> latin1_facet;
std::locale latin1_locale(std::locale(), latin1_facet);
fs::create_directory(fs::path(latin1_string, latin1_locale));
For POSIX-based operating systems, the path is constructed by first usinglatin1_facet to convert ISO/IEC 8859-1 encodedlatin1_string to a wide character string in the native wide
encoding ([[fs.path.type.cvt]](fs.path.type.cvt "31.12.6.3.2Type and encoding conversions"))[.](#7.sentence-3)
The resulting wide string is then
converted to an ordinary character
pathname string in the current native ordinary encoding[.](#7.sentence-4)
If the
native wide encoding is UTF-16 or UTF-32, and the current native ordinary
encoding is UTF-8, all of the characters in the ISO/IEC 8859-1 character set
will be converted to their Unicode representation, but for other native
ordinary encodings some characters may have no representation[.](#7.sentence-5)
For Windows-based operating systems, the path is constructed by
using latin1_facet to convert ISO/IEC 8859-1 encodedlatin1_string to a UTF-16 encoded wide character pathname
string[.](#7.sentence-6)
All of the characters in the ISO/IEC 8859-1 character set will be
converted to their Unicode representation[.](#7.sentence-7)
— *end example*]