Skip to content

Latest commit

 

History

History
71 lines (54 loc) · 1.35 KB

File metadata and controls

71 lines (54 loc) · 1.35 KB

operator<=>

  • filesystem[meta header]
  • std::filesystem[meta namespace]
  • path[meta class]
  • function[meta id-type]
  • cpp20[meta cpp]
friend strong_ordering operator<=>(const path& lhs, const path& rhs) noexcept; // (1) C++20

概要

三方比較を行う

戻り値

return lhs.compare(rhs) <=> 0;
  • compare[link compare.md]

備考

  • この演算子により、以下の演算子が使用可能になる:
    • operator<
    • operator<=
    • operator>
    • operator>=

#include <cassert>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  fs::path a = "a/b/c";
  fs::path b = "a/b/d";

  assert((a <=> a) == 0);
  assert((a <=> b) != 0);

  // 正規化は考慮されない。
  // ファイルシステムとしてのパスの等価性ではなく、
  // パス文字列の同値性が比較されれる
  fs::path c = "a/../b/c";
  assert((a <=> c) != 0);
}
  • <=>[color ff0000]

出力

バージョン

言語

  • C++20

処理系

参照