std::chrono::year_month_weekday::operator+=, std::chrono::year_month_weekday::operator-=
From cppreference.com
< cpp | chrono | year month weekday
| constexpr std::chrono::year_month_weekday& operator+=( const std::chrono::years& dy ) const noexcept; |
(1) | (C++20以降) |
| constexpr std::chrono::year_month_weekday& operator+=( const std::chrono::months& dm ) const noexcept; |
(2) | (C++20以降) |
| constexpr std::chrono::year_month_weekday& operator-=( const std::chrono::years& dy ) const noexcept; |
(3) | (C++20以降) |
| constexpr std::chrono::year_month_weekday& 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::years と std::chrono::months の両方に変換可能な期間の場合、呼び出しが曖昧になる可能性がある場合は、years オーバーロード (1,3) が優先されます。
[編集] 例
このコードを実行
#include <cassert> #include <chrono> #include <iostream> int main() { auto ymwi{1/std::chrono::Wednesday[2]/2021}; std::cout << ymwi << '\n'; ymwi += std::chrono::years(5); std::cout << ymwi << '\n'; assert(static_cast<std::chrono::year_month_day>(ymwi) == std::chrono::year(2026)/1/14); ymwi -= std::chrono::months(1); std::cout << ymwi << '\n'; assert(static_cast<std::chrono::year_month_day>(ymwi) == std::chrono::day(10)/12/2025); }
出力
2021/Jan/Wed[2] 2026/Jan/Wed[2] 2025/Dec/Wed[2]
[編集] 関連項目
| (C++20) |
year_month_weekday と年または月の数値を加算または減算する(関数) |