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

4.8 KiB

[fs.path.modifiers]

31 Input/output library [input.output]

31.12 File systems [filesystems]

31.12.6 Class path [fs.class.path]

31.12.6.5 Members [fs.path.member]

31.12.6.5.5 Modifiers [fs.path.modifiers]

🔗

void clear() noexcept;

1

#

Postconditions: empty() is true.

🔗

path& make_preferred();

2

#

Effects: Each directory-separator of the pathname in the generic format is converted to preferred-separator.

3

#

Returns: *this.

4

#

[Example 1: path p("foo/bar"); std::cout << p << '\n'; p.make_preferred(); std::cout << p << '\n';

On an operating system where preferred-separator is a slash, the output is:"foo/bar""foo/bar"

On an operating system where preferred-separator is a backslash, the output is:"foo/bar""foo\bar"

— end example]

🔗

path& remove_filename();

5

#

Effects: Remove the generic format pathname of filename() from the generic format pathname.

6

#

Postconditions: !has_filename().

7

#

Returns: *this.

8

#

[Example 2: path("foo/bar").remove_filename(); // yields "foo/" path("foo/").remove_filename(); // yields "foo/" path("/foo").remove_filename(); // yields "/" path("/").remove_filename(); // yields "/" — end example]

🔗

path& replace_filename(const path& replacement);

9

#

Effects: Equivalent to:remove_filename();operator/=(replacement);

10

#

Returns: *this.

11

#

[Example 3: path("/foo").replace_filename("bar"); // yields "/bar" on POSIX path("/").replace_filename("bar"); // yields "/bar" on POSIX — end example]

🔗

path& replace_extension(const path& replacement = path());

12

#

Effects:

Any existing extension() ([fs.path.decompose]) is removed from the pathname in the generic format, then

If replacement is not empty and does not begin with a dot character, a dot character is appended to the pathname in the generic format, then

operator+=(replacement);.

13

#

Returns: *this.

🔗

void swap(path& rhs) noexcept;

14

#

Effects: Swaps the contents (in all formats) of the two paths.

15

#

Complexity: Constant time.