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 起)

比较两个 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);
}