Namespaces
Variants

operator==,!=,<,<=,>,>=,<=> (std::filesystem::path)

From cppreference.net
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 指令 时发生不期望的类型转换。

< <= > >= != 运算符分别由 operator <=> operator == 自动合成。

(since C++20)

目录

参数

lhs, rhs - 要比较的路径

返回值

1-6) true 若对应的比较结果为真, false 否则。
7) std :: strong_ordering :: less lhs 小于 rhs ,否则为 std :: strong_ordering :: greater rhs 小于 lhs ,否则为 std :: strong_ordering :: equal

注释

路径相等性和等价性具有不同的语义。

在相等性判断中,如通过 operator== 所确定的,仅比较词法表示。因此, path ( "a" ) == path ( "b" ) 永远不会为 true

在等价情况下,通过 std::filesystem::equivalent() 判定时,会检查两个路径是否 解析 为同一文件系统对象。因此当路径解析为同一文件时, equivalent ( "a" , "b" ) 将返回 true

示例

缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的C++标准。

缺陷报告 适用范围 发布时行为 正确行为
LWG 3065 C++17 在存在 using-directive 的情况下允许所有可转换为 path 类型的比较操作 改为隐藏友元

参见

按字典序比较两个路径的词法表示
(公开成员函数)
(C++17)
检查两个路径是否指向同一文件系统对象
(函数)