[fs.path.gen] (original) (raw)

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;

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.

[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;

Effects: If:

returns path().

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

Then,

Returns: *this made relative to base.

[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_]

[Note 2:

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

— _end note_]

[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;

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

Otherwise return *this.

[Note 4:

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

— _end note_]

[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_]