| Member types | ||||||||||||||||||||||||||
| Member constants | ||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| Path decomposition | ||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| Helper classes | ||||||||||||||||||||||||||
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) |
[a, end()).Contents |
(none)
May throw implementation-defined exceptions.
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 oflexically_relative andlexically_proximate, seerelative andproximate.
On Windows, the returnedpath has backslashes (the preferred separators).
On POSIX, no filename in a relative path is acceptable as aroot-name.
#include <cassert>#include <filesystem>#include <iostream>namespace fs= std::filesystem; int main(){assert(fs::path("a/./b/..").lexically_normal()=="a/");assert(fs::path("a/.///b/../").lexically_normal()=="a/");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");assert(fs::path("a/b").lexically_relative("/a/b")=="");assert(fs::path("a/b").lexically_proximate("/a/b")=="a/b");}
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 3070 | C++17 | a filename that can also be a root-name may cause surprising result | treated as error case |
| LWG 3096 | C++17 | trailing "/" and "/." are handled incorrectly | corrected |
(C++17) | composes a relative path (function)[edit] |