命名空间
变体
操作

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

来自 cppreference.cn
 
 
 
 
定义于头文件 <chrono>
constexpr bool operator==( const std::chrono::year_month_day_last& x,
                           const std::chrono::year_month_day_last& y ) noexcept;
(1) (C++20 起)
constexpr std::strong_ordering

    operator<=>( const std::chrono::year_month_day_last& x,

                 const std::chrono::year_month_day_last& y ) noexcept;
(2) (C++20 起)

比较两个 year_month_day_lastxy。这是一个字典序比较:首先比较 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()

[编辑] 注意

如果 xy 都表示有效日期(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);
}