Namespaces
Variants

std::chrono:: operator+, std::chrono:: operator- (std::chrono::year_month_day_last)

From cppreference.net
(注:このHTML要素には翻訳対象のテキストコンテンツが含まれていないため、元の構造を保持したまま出力します)
ヘッダーで定義 <chrono>
(C++20以降)
(C++20以降)
(C++20以降)
(C++20以降)
(C++20以降)
(C++20以降)
1,2) dm. count ( ) ヶ月を ymdl が表す日付に加算します。結果は std:: chrono :: year_month ( ymdl. year ( ) , ymdl. month ( ) ) + dm と同じ year() および month() を持ちます。
3,4) dy. count ( ) 年を ymdl が表す日付に加算します。結果は std:: chrono :: year_month_day_last ( ymdl. year ( ) + dy, ymdl. month_day_last ( ) ) と等価です。
5) 指定された日付から dm. count ( ) ヶ月を減算します。 ymdl で表される日付から ymdl + - dm と等価です。
6) ymdl が表す日付から dy. count ( ) 年を減算します。 ymdl + - dy と等価です。

std::chrono::years std::chrono::months の両方に変換可能な期間型の場合、呼び出しが曖昧になる可能性があるときは years オーバーロード (3,4,6) が優先されます。

#include <cassert>
#include <chrono>
#include <iostream>
int main()
{
    auto ymdl{11/std::chrono::last/2020};
    std::cout << ymdl << '\n';
    ymdl = std::chrono::years(10) + ymdl;
    std::cout << ymdl << '\n';
    assert(ymdl == std::chrono::day(30)/
                   std::chrono::November/
                   std::chrono::year(2030));
    ymdl = ymdl - std::chrono::months(6);
    std::cout << ymdl << '\n';
    assert(ymdl == std::chrono::day(31)/
                   std::chrono::May/
                   std::chrono::year(2030));
}

出力:

2020/Nov/last
2030/Nov/last
2030/May/last