- chrono[meta header]
- std::chrono[meta namespace]
- year_month[meta class]
- function[meta id-type]
- cpp20[meta cpp]
constexpr year_month& operator-=(const months& dm) noexcept; // (1) C++20
constexpr year_month& operator-=(const years& dy) noexcept; // (2) C++20
year_month
の値に対して減算の複合代入を行う。
- (1) : 月の時間間隔を減算する
- (2) : 年の時間間隔を減算する
パラメータの型が、カレンダー時間のmonth
、year
ではなく、時間間隔を表すmonths
、years
であることに注意。
- (1) :
*this = *this - dm
- (2) :
*this = *this - dy
- (1), (2) :
*this
投げない
#include <iostream>
#include <chrono>
namespace chrono = std::chrono;
using namespace std::chrono_literals;
int main()
{
chrono::year_month date = 2020y/3;
date -= chrono::months{1}; // 1ヶ月戻す
date -= chrono::years{1}; // 1年戻す
std::cout << date << std::endl;
}
- 2020y[link /reference/chrono/year/op_y.md]
2019/Feb
- C++20
- Clang: 8.0 [mark verified]
- GCC: 11.1 [mark verified]
- Visual C++: 2019 Update 3 [mark noimpl]