operator==,!=,<,<=,>,>=,<=>(std::filesystem::path)
来自 cppreference.cn
< cpp | filesystem | path
friend bool operator==( const path& lhs, const path& rhs ) noexcept; |
(1) | (C++17 起) |
friend bool operator!=( const path& lhs, const path& rhs ) noexcept; |
(2) | (C++17 起) (直到 C++20) |
friend bool operator<( const path& lhs, const path& rhs ) noexcept; |
(3) | (C++17 起) (直到 C++20) |
friend bool operator<=( const path& lhs, const path& rhs ) noexcept; |
(4) | (C++17 起) (直到 C++20) |
friend bool operator>( const path& lhs, const path& rhs ) noexcept; |
(5) | (C++17 起) (直到 C++20) |
friend bool operator>=( const path& lhs, const path& rhs ) noexcept; |
(6) | (C++17 起) (直到 C++20) |
friend std::strong_ordering operator<=>( const path& lhs, const path& rhs ) noexcept; |
(7) | (C++20 起) |
按字典顺序比较两个路径。
1) 检查 lhs 和 rhs 是否相等。等价于 !(lhs < rhs) && !(rhs < lhs)。
2) 检查 lhs 和 rhs 是否不相等。等价于 !(lhs == rhs)。
3) 检查 lhs 是否小于 rhs。等价于 lhs.compare(rhs) < 0。
4) 检查 lhs 是否小于或等于 rhs。等价于 !(rhs < lhs)。
5) 检查 lhs 是否大于 rhs。等价于 rhs < lhs。
6) 检查 lhs 是否大于或等于 rhs。等价于 !(lhs < rhs)。
7) 获取 lhs 和 rhs 的三路比较结果。等价于 lhs.compare(rhs) <=> 0。
这些函数对于普通的非限定或限定查找是不可见的,并且只有当 std::filesystem::path 是参数的关联类时,才能通过实参依赖查找找到。这防止了在使用 using namespace std::filesystem; using-directive 时出现不期望的转换。
|
(C++20 起) |
目录 |
[编辑] 参数
lhs, rhs | - | 要比较的路径 |
[编辑] 返回值
1-6) 如果相应的比较产生 true,则为 true,否则为 false。
7) 如果 lhs 小于 rhs,则为 std::strong_ordering::less,如果 rhs 小于 lhs,则为 std::strong_ordering::greater,否则为 std::strong_ordering::equal。
[编辑] 注解
路径相等性和等效性具有不同的语义。
在相等性的情况下,如 operator==
所确定,仅比较词法表示。因此,path("a") == path("b") 永远不会为 true。
在等效性的情况下,如 std::filesystem::equivalent() 所确定,会检查两个路径是否解析为相同的文件系统对象。因此,如果路径解析为同一文件,则 equivalent("a", "b") 将返回 true。
[编辑] 示例
本节尚不完整 原因:没有示例 |
[编辑] 缺陷报告
以下行为更改缺陷报告被追溯应用于先前发布的 C++ 标准。
DR | 应用于 | 已发布行为 | 正确行为 |
---|---|---|---|
LWG 3065 | C++17 | 允许在存在 using-directive 的情况下比较所有可转换为 path 的内容 |
设为隐藏友元 |
[编辑] 参见
按字典顺序比较两个路径的词法表示 (公共成员函数) | |
(C++17) |
检查两个路径是否引用相同的文件系统对象 (函数) |