Difference between revisions of "cpp/filesystem/path/operator cmp"
m (→Notes: lc is available now) |
Andreas Krug (Talk | contribs) m (fmt, {{c}}) |
||
Line 2: | Line 2: | ||
{{cpp/filesystem/path/navbar}} | {{cpp/filesystem/path/navbar}} | ||
{{dcl begin}} | {{dcl begin}} | ||
− | {{dcl | num=1 | since=c++17 | 1= | + | {{dcl|num=1|since=c++17|1= |
friend bool operator==( const path& lhs, const path& rhs ) noexcept; | friend bool operator==( const path& lhs, const path& rhs ) noexcept; | ||
}} | }} | ||
− | {{dcl | num=2 | since=c++17 | until=c++20 | 1= | + | {{dcl|num=2|since=c++17|until=c++20|1= |
friend bool operator!=( const path& lhs, const path& rhs ) noexcept; | friend bool operator!=( const path& lhs, const path& rhs ) noexcept; | ||
}} | }} | ||
− | {{dcl | num=3 | since=c++17 | until=c++20 | 1= | + | {{dcl|num=3|since=c++17|until=c++20|1= |
friend bool operator<( const path& lhs, const path& rhs ) noexcept; | friend bool operator<( const path& lhs, const path& rhs ) noexcept; | ||
}} | }} | ||
− | {{dcl | num=4 | since=c++17 | until=c++20 | 1= | + | {{dcl|num=4|since=c++17|until=c++20|1= |
friend bool operator<=( const path& lhs, const path& rhs ) noexcept; | friend bool operator<=( const path& lhs, const path& rhs ) noexcept; | ||
}} | }} | ||
− | {{dcl | num=5 | since=c++17 | until=c++20 | 1= | + | {{dcl|num=5|since=c++17|until=c++20|1= |
friend bool operator>( const path& lhs, const path& rhs ) noexcept; | friend bool operator>( const path& lhs, const path& rhs ) noexcept; | ||
}} | }} | ||
− | {{dcl | num=6 | since=c++17 | until=c++20 | 1= | + | {{dcl|num=6|since=c++17|until=c++20|1= |
friend bool operator>=( const path& lhs, const path& rhs ) noexcept; | friend bool operator>=( const path& lhs, const path& rhs ) noexcept; | ||
}} | }} | ||
− | {{dcl | num=7 | since=c++20 | 1= | + | {{dcl|num=7|since=c++20|1= |
friend std::strong_ordering | friend std::strong_ordering | ||
operator<=>( const path& lhs, const path& rhs ) noexcept; | operator<=>( const path& lhs, const path& rhs ) noexcept; | ||
Line 28: | Line 28: | ||
Compares two paths lexicographically. | Compares two paths lexicographically. | ||
− | @1@ Checks whether {{ | + | @1@ Checks whether {{|lhs}} and {{|rhs}} are equal. Equivalent to {{c|!(lhs < rhs) && !(rhs < lhs)}}. |
− | @2@ Checks whether {{ | + | @2@ Checks whether {{|lhs}} and {{|rhs}} are not equal. Equivalent to {{c|!(lhs {{==}} rhs)}}. |
− | @3@ Checks whether {{ | + | @3@ Checks whether {{|lhs}} is less than {{|rhs}}. Equivalent to {{c|lhs.compare(rhs) < 0}}. |
− | @4@ Checks whether {{ | + | @4@ Checks whether {{|lhs}} is less than or equal to {{|rhs}}. Equivalent to {{c|!(rhs < lhs)}}. |
− | @5@ Checks whether {{ | + | @5@ Checks whether {{|lhs}} is greater than {{|rhs}}. Equivalent to {{c|rhs < lhs}}. |
− | @6@ Checks whether {{ | + | @6@ Checks whether {{|lhs}} is greater than or equal to {{|rhs}}. Equivalent to {{c|!(lhs < rhs)}}. |
− | @7@ Obtains the three-way comparison result of {{ | + | @7@ Obtains the three-way comparison result of {{|lhs}} and {{|rhs}}. Equivalent to {{c|1=lhs.compare(rhs) <=> 0}}. |
{{cpp/hidden friend|std::filesystem::path|plural=yes}} This prevents undesirable conversions in the presence of a {{c|using namespace std::filesystem;}} ''using-directive''. | {{cpp/hidden friend|std::filesystem::path|plural=yes}} This prevents undesirable conversions in the presence of a {{c|using namespace std::filesystem;}} ''using-directive''. | ||
− | {{rrev | since=c++20 | | + | {{rrev|since=c++20| |
{{cpp/note synthesized compare}} | {{cpp/note synthesized compare}} | ||
}} | }} | ||
Line 50: | Line 50: | ||
===Parameters=== | ===Parameters=== | ||
{{par begin}} | {{par begin}} | ||
− | {{par | lhs, rhs | the paths to compare}} | + | {{par|lhs, rhs|the paths to compare}} |
{{par end}} | {{par end}} | ||
===Return value=== | ===Return value=== | ||
@1-6@ {{c|true}} if the corresponding comparison yields, {{c|false}} otherwise. | @1-6@ {{c|true}} if the corresponding comparison yields, {{c|false}} otherwise. | ||
− | @7@ {{c|std::strong_ordering::less}} if {{ | + | @7@ {{c|std::strong_ordering::less}} if {{|lhs}} is less than {{|rhs}}, otherwise {{c|std::strong_ordering::greater}} if {{|rhs}} is less than {{|lhs}}, otherwise {{c|std::strong_ordering::equal}}. |
===Notes=== | ===Notes=== | ||
Line 74: | Line 74: | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/filesystem/path/dsc compare}} | + | {{dsc inc|cpp/filesystem/path/dsc compare}} |
− | {{dsc inc | cpp/filesystem/dsc equivalent}} | + | {{dsc inc|cpp/filesystem/dsc equivalent}} |
{{dsc end}} | {{dsc end}} | ||
{{langlinks|es|ja|ru|zh}} | {{langlinks|es|ja|ru|zh}} |
Latest revision as of 00:34, 16 August 2023
friend bool operator==( const path& lhs, const path& rhs ) noexcept; |
(1) | (since C++17) |
friend bool operator!=( const path& lhs, const path& rhs ) noexcept; |
(2) | (since C++17) (until C++20) |
friend bool operator<( const path& lhs, const path& rhs ) noexcept; |
(3) | (since C++17) (until C++20) |
friend bool operator<=( const path& lhs, const path& rhs ) noexcept; |
(4) | (since C++17) (until C++20) |
friend bool operator>( const path& lhs, const path& rhs ) noexcept; |
(5) | (since C++17) (until C++20) |
friend bool operator>=( const path& lhs, const path& rhs ) noexcept; |
(6) | (since C++17) (until C++20) |
friend std::strong_ordering operator<=>( const path& lhs, const path& rhs ) noexcept; |
(7) | (since C++20) |
Compares two paths lexicographically.
These functions are not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::filesystem::path is an associated class of the arguments. This prevents undesirable conversions in the presence of a using namespace std::filesystem; using-directive.
The |
(since C++20) |
Contents |
[edit] Parameters
lhs, rhs | - | the paths to compare |
[edit] Return value
[edit] Notes
Path equality and equivalence have different semantics.
In the case of equality, as determined by operator==
, only lexical representations are compared. Therefore, path("a") == path("b") is never true.
In the case of equivalence, as determined by std::filesystem::equivalent(), it is checked whether two paths resolve to the same file system object. Thus equivalent("a", "b") will return true if the paths resolve to the same file.
[edit] Example
This section is incomplete Reason: no example |
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR | Applied to | Behavior as published | Correct behavior |
---|---|---|---|
LWG 3065 | C++17 | allowed comparison of everything convertible to path in the presence of a using-directive
|
made hidden friend |
[edit] See also
compares the lexical representations of two paths lexicographically (public member function) | |
(C++17) |
checks whether two paths refer to the same file system object (function) |