名前空間
変種
操作

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

From cppreference.com
< 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以降)

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

1) lhsrhs が等しいかどうかをチェックします。!(lhs < rhs) && !(rhs < lhs) と同等です。
2) lhsrhs が等しくないかどうかをチェックします。!(lhs == rhs) と同等です。
3) lhsrhs より小さいかどうかをチェックします。lhs.compare(rhs) < 0 と同等です。
4) lhsrhs 以下かどうかをチェックします。!(rhs < lhs) と同等です。
5) lhsrhs より大きいかどうかをチェックします。rhs < lhs と同等です。
6) lhsrhs 以上かどうかをチェックします。!(lhs < rhs) と同等です。
7) lhsrhs の三方向比較の結果を取得します。lhs.compare(rhs) <=> 0 と同等です。

これらの関数は、通常の非修飾または修飾ルックアップからは見えず、`std::filesystem::path` が引数の関連クラスである場合にのみ、引数依存ルックアップによって見つけることができます。これにより、`using namespace std::filesystem;` のようなusing-directive が存在する場合に、望ましくない変換が発生するのを防ぎます。

<, <=, >, >=, != 演算子は、それぞれ operator<=>operator== から合成されます。

(C++20以降)

目次

[edit] Parameters

lhs, rhs - 比較するパス

[edit] Return value

1-6) 対応する比較が真である場合は true、そうでない場合は false
7) lhsrhs より小さい場合は std::strong_ordering::lessrhslhs より小さい場合は std::strong_ordering::greater、それ以外の場合は std::strong_ordering::equal

[edit] Notes

パスの等価性と同一性は、異なる意味を持ちます。

等価性(`operator==` によって決定される)の場合、比較されるのは字面上の表現のみです。したがって、path("a") == path("b") は決して true になりません。

同一性(std::filesystem::equivalent() によって決定される)の場合、2つのパスが同じファイルシステムオブジェクトに解決されるかどうかがチェックされます。したがって、パスが同じファイルに解決される場合、equivalent("a", "b")true を返します。

[edit] Example

[edit] Defect reports

以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。

DR 適用対象 公開された動作 正しい動作
LWG 3065 C++17 using-directive が存在する場合に、`path` に変換可能なあらゆるものを比較することを許可していました。 隠しフレンドにした。

[edit] See also

2つのパスの字列表現を辞書順に比較します
(public member function) [編集]
2つのパスが同じファイルシステムオブジェクトを参照しているか確認する
(関数) [編集]
English 日本語 中文(简体) 中文(繁體)