[fs.path.gen] # 31 Input/output library [[input.output]](./#input.output) ## 31.12 File systems [[filesystems]](filesystems#fs.path.gen) ### 31.12.6 Class path [[fs.class.path]](fs.class.path#fs.path.gen) #### 31.12.6.5 Members [[fs.path.member]](fs.path.member#fs.path.gen) #### 31.12.6.5.11 Generation [fs.path.gen] [🔗](#lib:lexically_normal,path) `path lexically_normal() const; ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L15144) *Returns*: A path whose pathname in the generic format is the normal form ([[fs.path.generic]](fs.path.generic "31.12.6.2 Generic pathname format")) of the pathname in the generic format of *this[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L15150) [*Example [1](#example-1)*: assert(path("foo/./bar/..").lexically_normal() == "foo/"); assert(path("foo/.///bar/../").lexically_normal() == "foo/"); The above assertions will succeed[.](#2.sentence-1) On Windows, the returned path's [*directory-separator*](fs.path.generic#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") characters will be backslashes rather than slashes, but that does not affect path equality[.](#2.sentence-2) — *end example*] [🔗](#lib:lexically_relative,path) `path lexically_relative(const path& base) const; ` [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L15169) *Effects*: If: - [(3.1)](#3.1) root_name() != base.root_name() is true, or - [(3.2)](#3.2) is_absolute() != base.is_absolute() is true, or - [(3.3)](#3.3) !has_root_directory() && base.has_root_directory() is true, or - [(3.4)](#3.4) any [*filename*](fs.path.generic#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") inrelative_path() or base.relative_path() can be interpreted as a [*root-name*](fs.path.generic#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]"), returns path()[.](#3.sentence-1) [*Note [1](#note-1)*: On a POSIX implementation, no [*filename*](fs.path.generic#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") in a [*relative-path*](fs.path.generic#nt:relative-path "31.12.6.2 Generic pathname format [fs.path.generic]") is acceptable as a [*root-name*](fs.path.generic#nt:root-name "31.12.6.2 Generic pathname format [fs.path.generic]")[.](#3.sentence-2) — *end note*] Determines the first mismatched element of *this and base as if by:auto [a, b] = mismatch(begin(), end(), base.begin(), base.end()); Then, - [(3.5)](#3.5) if a == end() and b == base.end(), returns path("."); otherwise - [(3.6)](#3.6) let n be the number of [*filename*](fs.path.generic#nt:filename "31.12.6.2 Generic pathname format [fs.path.generic]") elements in [b, base.end()) that are not dot or dot-dot or empty, minus the number that are dot-dot[.](#3.6.sentence-1) If n<0, returns path(); otherwise - [(3.7)](#3.7) if n == 0 and (a == end() || a->empty()), returns path("."); otherwise - [(3.8)](#3.8) returns an object of class path that is default-constructed, followed by * [(3.8.1)](#3.8.1) application of operator/=(path(".."))n times, and then * [(3.8.2)](#3.8.2) application of operator/= for each element in [a, end())[.](#3.8.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L15215) *Returns*: *this made relative to base[.](#4.sentence-1) Does not resolve ([[fs.class.path]](fs.class.path "31.12.6 Class path")) symlinks[.](#4.sentence-2) Does not first normalize ([[fs.path.generic]](fs.path.generic "31.12.6.2 Generic pathname format")) *this or base[.](#4.sentence-3) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L15221) [*Example [2](#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[.](#5.sentence-1) On Windows, the returned path's [*directory-separator*](fs.path.generic#nt:directory-separator "31.12.6.2 Generic pathname format [fs.path.generic]") characters will be backslashes rather than slashes, but that does not affect path equality[.](#5.sentence-2) — *end example*] [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L15237) [*Note [2](#note-2)*: If symlink following semantics are desired, use the operational function relative()[.](#6.sentence-1) — *end note*] [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L15243) [*Note [3](#note-3)*: If normalization ([[fs.path.generic]](fs.path.generic "31.12.6.2 Generic pathname format")) is needed to ensure consistent matching of elements, apply lexically_normal() to *this, base, or both[.](#7.sentence-1) — *end note*] [🔗](#lib:lexically_proximate,path) `path lexically_proximate(const path& base) const; ` [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L15258) *Returns*: If the value of lexically_relative(base) is not an empty path, return it[.](#8.sentence-1) Otherwise return *this[.](#8.sentence-2) [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L15263) [*Note [4](#note-4)*: If symlink following semantics are desired, use the operational function proximate()[.](#9.sentence-1) — *end note*] [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L15269) [*Note [5](#note-5)*: If normalization ([[fs.path.generic]](fs.path.generic "31.12.6.2 Generic pathname format")) is needed to ensure consistent matching of elements, apply lexically_normal() to *this, base, or both[.](#10.sentence-1) — *end note*]