namespace std::chrono {
constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept; // (1) C++20
constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept; // (2) C++20
}
概要
year_month_day
の減算を行う。
- (1) :
year_month_day
から月の時間間隔を減算する - (2) :
year_month_day
から年の時間間隔を減算する
テンプレートパラメータ制約
戻り値
- (1) :
return ymd + (-dm);
- (2) :
return ymd + (-dy);
例外
投げない
備考
- 日の値が29以上である場合、減算により年月の値によっては範囲外の日となり、
ok() == false
になる可能性がある
例
#include <cassert>
#include <chrono>
namespace chrono = std::chrono;
using namespace std::chrono_literals;
int main()
{
assert(2020y/3/1 - chrono::months{1} == 2020y/2/1);
assert(2020y/3/1 - chrono::years{1} == 2019y/3/1);
}
xxxxxxxxxx
#include <cassert>
#include <chrono>
namespace chrono = std::chrono;
using namespace std::chrono_literals;
int main()
{
assert(2020y/3/1 - chrono::months{1} == 2020y/2/1);
assert(2020y/3/1 - chrono::years{1} == 2019y/3/1);
}
出力
バージョン
言語
- C++20
処理系
- Clang: 8.0 ✅
- GCC: 9.2 ❌
- Visual C++: 2019 Update 3 ❌