名前空間
変種
操作

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

From cppreference.com
 
 
 
 
ヘッダー <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以降)

2つのyear_month_day_lastの値xyを比較します。これは辞書順比較です。まず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);
}
English 日本語 中文(简体) 中文(繁體)