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

履歴 編集

function
<chrono>

std::chrono::day::ok(C++20)

constexpr bool ok() const noexcept; // (1) C++20

概要

dayオブジェクトが保持する日の値が[1, 31]の範囲内かを判定する。

戻り値

コンストラクタで設定されて保持している日を表す値dがあるとして、以下を返す:

return 1 <= d && d <= 31;

備考

  • この関数は、値の妥当性を検証するのではなく、カレンダー範囲の値をもっているかの判定をする

#include <cassert>
#include <chrono>

namespace chrono = std::chrono;

int main()
{
  chrono::day d{1};
  assert(d.ok());

  assert(!chrono::day{0}.ok());
  assert(!chrono::day{32}.ok());
}

出力

バージョン

言語

  • C++20

処理系

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