名前空間
変種
操作

std::chrono::year_month_weekday_last::operator+=、std::chrono::year_month_weekday_last::operator-=

From cppreference.com
 
 
 
 
constexpr std::chrono::year_month_weekday_last&
    operator+=( const std::chrono::years& dy ) const noexcept;
(1) (C++20以降)
constexpr std::chrono::year_month_weekday_last&
    operator+=( const std::chrono::months& dm ) const noexcept;
(2) (C++20以降)
constexpr std::chrono::year_month_weekday_last&
    operator-=( const std::chrono::years& dy ) const noexcept;
(3) (C++20以降)
constexpr std::chrono::year_month_weekday_last&
    operator-=( const std::chrono::months& dm ) const noexcept;
(4) (C++20以降)

指定された期間 dy または dm によって、時間点 *this を変更します。

1) *this = *this + dy; と同等です。
2) *this = *this + dm; と同等です。
3) *this = *this - dy; と同等です。
4) *this = *this - dm; と同等です。

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

[編集]

#include <chrono>
#include <iostream>
using namespace std::chrono;
 
int main()
{
    auto ymwdl{August/Friday[last]/2022};
    std::cout << year_month_day{ymwdl} << '\n';
    ymwdl += months(2);
    std::cout << year_month_day{ymwdl} << '\n';
    ymwdl -= years(1); 
    std::cout << year_month_day{ymwdl} << '\n';
}

出力

2022-08-26
2022-10-28
2021-10-29

[編集] 関連項目

year_month_weekday_last と年または月の数値を加算または減算する
(関数) [edit]
English 日本語 中文(简体) 中文(繁體)