Skip to content

Latest commit

 

History

History
108 lines (81 loc) · 2.73 KB

File metadata and controls

108 lines (81 loc) · 2.73 KB

operator+

  • chrono[meta header]
  • std::chrono[meta namespace]
  • function[meta id-type]
  • cpp20[meta cpp]
namespace std::chrono {
  constexpr year_month_weekday
    operator+(const year_month_weekday& ymwd,
              const months& dm) noexcept;               // (1) C++20
  constexpr year_month_weekday
    operator+(const months& dm,
              const year_month_weekday& ymwd) noexcept; // (2) C++20

  constexpr year_month_weekday
    operator+(const year_month_weekday& ymwd,
              const years& dy) noexcept;                // (3) C++20
  constexpr year_month_weekday
    operator+(const years& dy,
              const year_month_weekday& ymwd) noexcept; // (4) C++20
}

概要

year_month_weekdayの加算を行う。

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

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

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

戻り値

  • (1) :
return (ymwd.year() / ymwd.month() + dm) / ymwd.weekday_indexed();
  • ymwd.year()[link year.md]
  • ymwd.month()[link month.md]
  • ymwd.weekday_indexed()[link weekday_indexed.md]
  • (2) :
return ymwd + dm;
  • (3) :
return (ymwd.year() + dy) / ymwd.month() / ymwd.weekday_indexed();
  • ymwd.year()[link year.md]
  • ymwd.month()[link month.md]
  • ymwd.weekday_indexed()[link weekday_indexed.md]
  • (4) :
return ymwd + dy;

例外

投げない

#include <cassert>
#include <chrono>

namespace chrono = std::chrono;
using namespace std::chrono_literals;

int main()
{
  assert(2020y/2/chrono::Sunday[2] + chrono::months{1} == 2020y/3/chrono::Sunday[2]);
  assert(2019y/3/chrono::Sunday[2] + chrono::years{1} == 2020y/3/chrono::Sunday[2]);
}
  • 2019y[link /reference/chrono/year/op_y.md]
  • 2020y[link /reference/chrono/year/op_y.md]
  • chrono::Sunday[link /reference/chrono/weekday_constants.md]

出力

バージョン

言語

  • C++20

処理系

参照