30 Input/output library [input.output]

30.10 File systems [filesystems]

30.10.8 Class path [fs.class.path]

30.10.8.4 path members [fs.path.member]

30.10.8.4.11 path generation [fs.path.gen]

path lexically_normal() const;

Returns: A path whose pathname in the generic format is the normal form of the pathname in the generic format of *this.

[Example:

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;

Returns: *this made relative to base. Does not resolve symlinks. Does not first normalize *this or base.

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, returns path(). Determines the first mismatched element of *this and base as if by:

auto [a, b] = mismatch(begin(), end(), base.begin(), base.end());

Then,

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

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

  • 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()).

[Example:

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: If symlink following semantics are desired, use the operational function relative(). end note]

[Note: If normalization 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: If symlink following semantics are desired, use the operational function proximate(). end note]

[Note: If normalization is needed to ensure consistent matching of elements, apply lexically_­normal() to *this, base, or both. end note]