Namespaces
Variants

std::chrono:: operator==,<=> (std::chrono::year_month_day_last)

From cppreference.net
ヘッダーで定義 <chrono>
constexpr bool operator == ( const std:: chrono :: year_month_day_last & x,
const std:: chrono :: year_month_day_last & y ) noexcept ;
(1) (C++20以降)
(2) (C++20以降)

2つの year_month_day_last 値を x y で比較します。これは辞書式比較です:最初に year() が比較され、次に month() が比較されます。

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

戻り値

1) x. year ( ) == y. year ( ) && x. month ( ) == y. month ( )
2) x. year ( ) <=> y. year ( ) ! = 0 ? x. year ( ) <=> y. year ( ) : x. month ( ) <=> y. month ( )

注記

x y の両方が有効な日付を表す場合( x. ok ( ) && y. ok ( ) == true )、辞書順比較の結果は暦順と一致します。

#include <cassert>
#include <chrono>
#include <iostream>
int main()
{
    auto ymdl1{11/std::chrono::last/2020};
    auto mdl{std::chrono::last/std::chrono::November};
    auto ymdl2{mdl/2020};
    assert(ymdl1 == ymdl2);
    ymdl1 -= std::chrono::months{2};
    ymdl2 -= std::chrono::months{1};
    assert(ymdl1 < ymdl2);
}