名前空間
変種

std::chrono::year_month::operator+=, std::chrono::year_month::operator-=

提供: cppreference.com
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
日付と時間のユーティリティ
(C++11)
(C++11)
時刻
(C++20)



(C++20)(C++20)(C++20)(C++20)
時計
(C++20)
                                             
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
カレンダー
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
タイムゾーン
(C++20)
(C++20)
(C++20)
(C++20)
C スタイルの日付と時間
 
 
<tbody> </tbody>
constexpr std::chrono::year_month& operator+=(const std::chrono::years& dy) const noexcept;
(1) (C++20以上)
constexpr std::chrono::year_month& operator+=(const std::chrono::months& dm) const noexcept;
(2) (C++20以上)
constexpr std::chrono::year_month& operator-=(const std::chrono::years& dy) const noexcept;
(3) (C++20以上)
constexpr std::chrono::year_month& operator-=(const std::chrono::months& dm) const noexcept;
(4) (C++20以上)

時点 *this の表現を時間 dy 年または dm ヶ月変更します。

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

ノート

std::chrono::months に変換可能だけれども std::chrono::years には変換できない duration は、 year_month に直接加算または減算できます。 std::chrono::years に変換可能な duration は、できません。 std::chrono::months にも変換可能なため、曖昧な結果となります。

using namespace std::chrono;

using decades = duration<int, std::ratio_multiply<std::ratio<10>, years::period>>;
using kilomonths = duration<int, std::ratio_multiply<std::kilo, months::period>>;

auto ym = 2001y/April;
ym += decades{1}; // error, ambiguous
ym += kilomonths{1}; // OK

関連項目

year_month に対する算術演算を行います
(関数) [edit]