• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <chrono>

    std::chrono::weekday_indexed::ok

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

    概要

    weekday_indexedオブジェクトが保持する曜日とインデックスが妥当な範囲内にあるかを判定する。

    戻り値

    コンストラクタで設定されて保持している曜日を表す値wd_、およびインデックス値index_があるとして、以下を返す:

    return wd_.ok() && 1 <= index_ && index_ <= 5;
    

    備考

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

    #include <cassert>
    #include <chrono>
    
    namespace chrono = std::chrono;
    
    int main()
    {
      assert(chrono::Sunday[1].ok());
      assert(!chrono::Sunday[0].ok());
      assert(!chrono::Sunday[6].ok());
      assert(!(chrono::weekday_indexed{chrono::weekday{8}, 1}).ok());
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系