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 in
relative_path() or base.relative_path()
can be interpreted as a root-name,
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 or empty, minus the number that are dot-dot
. If n<0, returns path(); otherwise
if n == 0 and (a == end() || a->empty(),
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 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
. [
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]