- 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
- Clang:
- GCC: 10
- Visual C++: ??
- P1614R2 The Mothership has Landed
- C++20での三方比較演算子の追加と、関連する演算子の自動導出