27 Input/output library [input.output]

27.10 File systems [filesystems]

27.10.8 Class path [class.path]

27.10.8.4 path members [path.member]

27.10.8.4.11 path generation [path.gen]

path lexically_normal() const;

Returns: *this in normal form ([fs.def.normal.form]).

Example:

assert(path("foo/./bar/..").lexically_normal() == "foo");
assert(path("foo/.///bar/../").lexically_normal() == "foo/.");

The above assertions will succeed. The second example ends with a current directory (dot) element appended to support operating systems that use different syntax for directory names and regular file names.

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 ([fs.def.pathres]) symlinks. Does not first normalize ([fs.def.normal.form]) *this or base.

Effects: 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 == begin() and b == base.begin(), returns path(); otherwise

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

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

    • application of operator/=(path("..")) for each element in [b, base.end()), 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") == "");

The above assertions will succeed. On Windows, the returned path's directory-separator characters will be backslashes rather than forward 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 ([fs.def.normal.form]) 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 ([fs.def.normal.form]) is needed to ensure consistent matching of elements, apply lexically_normal() to *this, base, or both.  — end note ]