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

履歴 編集

function
<chrono>

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

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

概要

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

戻り値

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

return 1 <= m && m <= 12;

備考

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

#include <cassert>
#include <chrono>

namespace chrono = std::chrono;

int main()
{
  chrono::month m{1};
  assert(m.ok());

  assert(!chrono::month{0}.ok());
  assert(!chrono::month{13}.ok());
}

出力

バージョン

言語

  • C++20

処理系

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