最終更新日時(UTC):
が更新

履歴 編集

function
<chrono>

std::chrono::year_month_day_last::operator+=(C++20)

constexpr year_month_day_last& operator+=(const months& m) noexcept; // (1) C++20
constexpr year_month_day_last& operator+=(const years& y) noexcept;  // (2) C++20

概要

year_month_day_lastの値に対して加算の複合代入を行う。

  • (1) : 月の時間間隔を加算する
  • (2) : 年の時間間隔を加算する

パラメータの型が、カレンダー時間のmonthyearではなく、時間間隔を表すmonthsyearsであることに注意。

テンプレートパラメータ制約

  • (1) : monthsパラメータに指定した引数がyearsに変換可能である場合、yearsへの暗黙変換は、monthsへの暗黙変換よりも劣る

効果

  • (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_day_last date = 2019y/1/chrono::last;

  date += chrono::months{1}; // 1ヶ月進める
  date += chrono::years{1};  // 1年進める

  assert(chrono::year_month_day{date} == 2020y/2/29);
}

出力

バージョン

言語

  • C++20

処理系

参照