Difference between revisions of "cpp/filesystem/path/operator cmp"
From cppreference.com
< cpp | filesystem | path
(P1614R2) |
Andreas Krug (Talk | contribs) m (fmt, {{c}}) |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | {{title|1=operator==,!=,<,<=,>,>={{small|(std::filesystem::path)}}}} | + | {{title|1=operator==,!=,<,<=,>,>={{small|(std::filesystem::path)}}}} |
{{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= |
− | bool operator==( const path& lhs, const path& rhs ) noexcept; | + | 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= |
− | bool operator!=( const path& lhs, const path& rhs ) noexcept; | + | 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= |
− | bool operator<( const path& lhs, const path& rhs ) noexcept; | + | 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= |
− | bool operator<=( const path& lhs, const path& rhs ) noexcept; | + | 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= |
− | bool operator>( const path& lhs, const path& rhs ) noexcept; | + | 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= |
− | bool operator>=( const path& lhs, const path& rhs ) noexcept; | + | bool operator>=( const path& lhs, const path& rhs ) noexcept; |
}} | }} | ||
− | {{dcl | num=7 | since=c++20 | 1= | + | {{dcl|num=7|since=c++20|1= |
− | std::strong_ordering operator<=>( const path& lhs, const path& rhs ) noexcept; | + | std::strong_ordering |
+ | operator<=>( const path& lhs, const path& rhs ) noexcept; | ||
}} | }} | ||
{{dcl end}} | {{dcl end}} | ||
Line 27: | 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''. | ||
+ | |||
+ | |||
+ | |||
+ | |||
===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 57: | Line 62: | ||
In the case of equality, as determined by {{tt|operator{{==}}}}, only lexical representations are compared. Therefore, {{c|1=path("a") == path("b")}} is never {{c|true}}. | In the case of equality, as determined by {{tt|operator{{==}}}}, only lexical representations are compared. Therefore, {{c|1=path("a") == path("b")}} is never {{c|true}}. | ||
− | In the case of equivalence, as determined by {{ | + | In the case of equivalence, as determined by {{|filesystemequivalent}}, it is checked whether two paths ''resolve'' to the same file system object. Thus {{c|equivalent("a", "b")}} will return {{c|true}} if the paths resolve to the same file. |
+ | |||
+ | |||
+ | |||
===Defect reports=== | ===Defect reports=== | ||
Line 66: | 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 end}} | {{dsc end}} | ||
− | {{langlinks|ja|zh}} | + | {{langlinks|ja|zh}} |