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以降)

2つのパスを辞書順に比較します。

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 と等価です。

これらの関数は通常の unqualified lookup qualified lookup では可視化されず、 argument-dependent lookup によってのみ、std::filesystem::pathが引数の関連クラスである場合に見つけることができます。これは using namespace std :: filesystem ; using-directive が存在する場合の望ましくない変換を防ぎます。

< <= > >= および != 演算子は、 合成されます (それぞれ operator <=> および operator == から)。

(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() によって決定されるように、2つのパスが同じファイルシステムオブジェクトに 解決される かどうかがチェックされます。したがって equivalent ( "a" , "b" ) は、パスが同じファイルに解決される場合に true を返します。

不具合報告

以下の動作変更欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。

DR 適用対象 公開時の動作 正しい動作
LWG 3065 C++17 using-directive が存在する場合、 path に変換可能なすべての比較を許可していた 隠れフレンド関数に変更

関連項目

2つのパスの字句表現を辞書順に比較する
(公開メンバ関数)
(C++17)
2つのパスが同じファイルシステムオブジェクトを参照しているかチェックする
(関数)