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

履歴 編集

function
<chrono>

std::chrono::operator-(C++20)

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) : monthsパラメータに指定した引数がyearsに変換可能である場合、yearsへの暗黙変換は、monthsへの暗黙変換よりも劣る

戻り値

  • (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);
}

出力

バージョン

言語

  • C++20

処理系

  • Clang: 8.0
  • GCC: (9.2時点で実装なし)
  • Visual C++: (2019 Update 3時点で実装なし)

参照