std::filesystem::path::lexically_normal,std::filesystem::path::lexically_relative, (3) - Linux Manuals
std::filesystem::path::lexically_normal,std::filesystem::path::lexically_relative,: std::filesystem::path::lexically_normal,std::filesystem::path::lexically_relative,
Command to display std::filesystem::path::lexically_normal,std::filesystem::path::lexically_relative,
manual in Linux: $ man 3 std::filesystem::path::lexically_normal,std::filesystem::path::lexically_relative,
NAME
std::filesystem::path::lexically_normal,std::filesystem::path::lexically_relative, - std::filesystem::path::lexically_normal,std::filesystem::path::lexically_relative,
Synopsis
path lexically_normal() const; (1) (since C++17)
path lexically_relative(const path& base) const; (2) (since C++17)
path lexically_proximate(const path& base) const; (3) (since C++17)
1) Returns *this converted to normal form in its generic format
2) Returns *this made relative to base.
* First, if root_name() != base.root_name() || is_absolute() != base.is_absolute()
|| (!has_root_directory() && base.has_root_directory()), returns a
default-constructed path.
* Otherwise, first 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, define N as the number of nonempty filename elements that are neither
dot nor dot-dot in [b, base.end()), minus the number of dot-dot filename
elements, If N < 0, returns a default-constructed path.
* otherwise, if N = 0 and a == end() || a->empty(), returns path(".").
* otherwise returns an object composed from
* a default-constructed path() followed by
* N applications of operator/=(path("..")), followed by
* one application of operator/= for each element in the half-open range [a, end())
3) If the value of lexically_relative(base) is not an empty path, return it.
Otherwise return *this.
Parameters
(none)
Return value
1) The normal form of the path
2) The relative form of the path
3) The proximate form of the path
Exceptions
(none)
Notes
These conversions are purely lexical. They do not check that the paths exist, do not
follow symlinks, and do not access the filesystem at all. For symlink-following
counterparts of lexically_relative and lexically_proximate, see relative and
proximate.
On Windows, the returned path has backslashes (the preferred separators),
Example
// Run this code
#include <iostream>
#include <filesystem>
#include <cassert>
namespace fs = std::filesystem;
int main()
{
assert(fs::path("foo/./bar/..").lexically_normal() == "foo/");
assert(fs::path("foo/.///bar/../").lexically_normal() == "foo/");
assert(fs::path("/a/d").lexically_relative("/a/b/c") == "../../d");
assert(fs::path("/a/b/c").lexically_relative("/a/d") == "../b/c");
assert(fs::path("a/b/c").lexically_relative("a") == "b/c");
assert(fs::path("a/b/c").lexically_relative("a/b/c/x/y") == "../..");
assert(fs::path("a/b/c").lexically_relative("a/b/c") == ".");
assert(fs::path("a/b").lexically_relative("c/d") == "../../a/b");
}
Defect reports
The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.
DR Applied to Behavior as published Correct behavior
LWG 3096 C++17 trailing "/" and "/." are handled incorrectly corrected
See also
relative composes a relative path
proximate (function)
(C++17)
Pages related to std::filesystem::path::lexically_normal,std::filesystem::path::lexically_relative,
- std::filesystem::path::lexically_normal,std::filesystem::path::lexically_relative,std::filesystem::path::lexically_proximate (3) - std::filesystem::path::lexically_normal,std::filesystem::path::lexically_relative,std::filesystem::path::lexically_proximate
- std::filesystem::path::assign (3) - std::filesystem::path::assign
- std::filesystem::path::begin,std::filesystem::path::end (3) - std::filesystem::path::begin,std::filesystem::path::end
- std::filesystem::path::c_str,std::filesystem::path::native, (3) - std::filesystem::path::c_str,std::filesystem::path::native,
- std::filesystem::path::c_str,std::filesystem::path::native,std::filesystem::path::operatorstring_type() (3) - std::filesystem::path::c_str,std::filesystem::path::native,std::filesystem::path::operatorstring_type()
- std::filesystem::path::clear (3) - std::filesystem::path::clear
- std::filesystem::path::compare (3) - std::filesystem::path::compare
- std::filesystem::path::concat,std::filesystem::path::operator+= (3) - std::filesystem::path::concat,std::filesystem::path::operator+=
- std::filesystem::path::empty (3) - std::filesystem::path::empty
- std::filesystem::path::extension (3) - std::filesystem::path::extension
- std::filesystem::path::filename (3) - std::filesystem::path::filename
- std::filesystem::path::format (3) - std::filesystem::path::format
- std::filesystem::path::generic_string,std::filesystem::path::generic_wstring, (3) - std::filesystem::path::generic_string,std::filesystem::path::generic_wstring,
- std::filesystem::path::has_root_path,std::filesystem::path::has_root_name, (3) - std::filesystem::path::has_root_path,std::filesystem::path::has_root_name,
- std::filesystem::path::is_absolute,is_relative (3) - std::filesystem::path::is_absolute,is_relative
- std::filesystem::path::make_preferred (3) - std::filesystem::path::make_preferred
- std::filesystem::path::operator= (3) - std::filesystem::path::operator=
- std::filesystem::path::parent_path (3) - std::filesystem::path::parent_path
- std::filesystem::path::path (3) - std::filesystem::path::path
- std::filesystem::path::relative_path (3) - std::filesystem::path::relative_path
- std::filesystem::path::remove_filename (3) - std::filesystem::path::remove_filename
- std::filesystem::path::replace_extension (3) - std::filesystem::path::replace_extension
- std::filesystem::path::replace_filename (3) - std::filesystem::path::replace_filename
- std::filesystem::path::root_directory (3) - std::filesystem::path::root_directory
- std::filesystem::path::root_name (3) - std::filesystem::path::root_name
- std::filesystem::path::root_path (3) - std::filesystem::path::root_path
- std::filesystem::path::stem (3) - std::filesystem::path::stem