- chrono[meta header]
- std::chrono[meta namespace]
- year_month_weekday[meta class]
- function[meta id-type]
- cpp20[meta cpp]
constexpr year_month_weekday& operator+=(const months& m) noexcept; // (1) C++20
constexpr year_month_weekday& operator+=(const years& y) noexcept; // (2) C++20year_month_weekdayの値に対して加算の複合代入を行う。
- (1) : 月の時間間隔を加算する
- (2) : 年の時間間隔を加算する
パラメータの型が、カレンダー時間のmonth、yearではなく、時間間隔を表すmonths、yearsであることに注意。
- (1) :
*this = *this + m - (2) :
*this = *this + y
- (1), (2) :
*this
投げない
#include <cassert>
#include <chrono>
namespace chrono = std::chrono;
using namespace std::chrono_literals;
int main()
{
chrono::year_month_weekday date = 2019y/2/chrono::Sunday[2];
date += chrono::months{1}; // 1ヶ月進める
date += chrono::years{1}; // 1年進める
assert(chrono::year_month_day{chrono::sys_days{date}} == 2020y/3/8);
}- 2019y[link /reference/chrono/year/op_y.md]
- 2020y[link /reference/chrono/year/op_y.md]
- chrono::Sunday[link /reference/chrono/weekday_constants.md]
- chrono::year_month_day[link /reference/chrono/year_month_day.md]
- chrono::sys_days[link /reference/chrono/sys_time.md]
- C++20
- Clang: 8.0
- GCC: 11.1
- Visual C++: (2019 Update 3時点で実装なし)