path lexically_normal() const;
|
(1) | (C++17 起) |
path lexically_relative(const path& base) const;
|
(2) | (C++17 起) |
path lexically_proximate(const path& base) const;
|
(3) | (C++17 起) |
base
的 *this
。
*this
和 base
的首个不匹配元素,如同以 auto [a, b] = mismatch(begin(), end(), base.begin(), base.end()) ,然后
[a, end())
中的每个元素应用一次 operator/=*this
。目录 |
(无)
(无)
这些转换是纯字典的。它们不检查路径是否存在,不跟随符号链接,且完全不访问文件系统。关于 lexically_relative
与 lexically_proximate
跟随符号链接的对应版本,见 relative 与 proximate。
Windows 上返回路径拥有反斜杠(偏好分隔符)。
#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(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"); }
(C++17)
|
组成一个相对路径 (函数) |