Files
2025-10-25 03:02:53 +03:00

6.2 KiB

[fs.path.gen]

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.11 Generation [fs.path.gen]

🔗

path lexically_normal() const;

1

#

Returns: A path whose pathname in the generic format is the normal form ([fs.path.generic]) of the pathname in the generic format of *this.

2

#

[Example 1: assert(path("foo/./bar/..").lexically_normal() == "foo/"); assert(path("foo/.///bar/../").lexically_normal() == "foo/");

The above assertions will succeed.

On Windows, the returned path's directory-separator characters will be backslashes rather than slashes, but that does not affect path equality.

— end example]

🔗

path lexically_relative(const path& base) const;

3

#

Effects: If:

root_name() != base.root_name() is true, or

is_absolute() != base.is_absolute() is true, or

!has_root_directory() && base.has_root_directory() is true, or

any filename inrelative_path() or base.relative_path() can be interpreted as a root-name,

returns path().

[Note 1:

On a POSIX implementation, no filename in a relative-path is acceptable as a root-name.

— end note]

Determines the first mismatched element of *this and base as if by:auto [a, b] = mismatch(begin(), end(), base.begin(), base.end());

Then,

  • (3.5)

    if a == end() and b == base.end(), returns path("."); otherwise

  • (3.6)

    let n be the number of filename elements in [b, base.end()) that are not dot or dot-dot or empty, minus the number that are dot-dot. If n<0, returns path(); otherwise

  • (3.7)

    if n == 0 and (a == end() || a->empty()), returns path("."); otherwise

  • (3.8)

    returns an object of class path that is default-constructed, followed by

application of operator/=(path(".."))n times, and then

application of operator/= for each element in [a, end()).

4

#

Returns: *this made relative to base.

Does not resolve ([fs.class.path]) symlinks.

Does not first normalize ([fs.path.generic]) *this or base.

5

#

[Example 2: assert(path("/a/d").lexically_relative("/a/b/c") == "../../d"); assert(path("/a/b/c").lexically_relative("/a/d") == "../b/c"); assert(path("a/b/c").lexically_relative("a") == "b/c"); assert(path("a/b/c").lexically_relative("a/b/c/x/y") == "../.."); assert(path("a/b/c").lexically_relative("a/b/c") == "."); assert(path("a/b").lexically_relative("c/d") == "../../a/b");

The above assertions will succeed.

On Windows, the returned path's directory-separator characters will be backslashes rather than slashes, but that does not affect path equality.

— end example]

6

#

[Note 2:

If symlink following semantics are desired, use the operational function relative().

— end note]

7

#

[Note 3:

If normalization ([fs.path.generic]) is needed to ensure consistent matching of elements, apply lexically_normal() to *this, base, or both.

— end note]

🔗

path lexically_proximate(const path& base) const;

8

#

Returns: If the value of lexically_relative(base) is not an empty path, return it.

Otherwise return *this.

9

#

[Note 4:

If symlink following semantics are desired, use the operational function proximate().

— end note]

10

#

[Note 5:

If normalization ([fs.path.generic]) is needed to ensure consistent matching of elements, apply lexically_normal() to *this, base, or both.

— end note]