• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <chrono>

    std::chrono::weekday::c_encoding

    constexpr unsigned int c_encoding() const noexcept; // (1) C++20
    

    概要

    weekdayオブジェクトが保持する曜日の値を、C / C++の仕様に基づき、日曜日から土曜日までを値の範囲[0, 6]として取得する。

    戻り値

    コンストラクタで設定された、日曜日から土曜日までの値範囲[0, 6]を持つ変数wdがあるとして、以下を返す:

    return wd;
    

    例外

    投げない

    備考

    • この仕様は、std::tmクラスのtm_wdayメンバ変数の値範囲に合わせたものである

    #include <iostream>
    #include <chrono>
    
    namespace chrono = std::chrono;
    
    int main()
    {
      chrono::weekday ar[] = {
        chrono::Sunday,
        chrono::Monday,
        chrono::Tuesday,
        chrono::Wednesday,
        chrono::Thursday,
        chrono::Friday,
        chrono::Saturday
      };
    
      for (chrono::weekday w : ar) {
        std::cout << w << " : " << w.c_encoding() << std::endl;
      }
    }
    

    出力

    Sunday : 0
    Monday : 1
    Tuesday : 2
    Wednesday : 3
    Thursday : 4
    Friday : 5
    Saturday : 6
    

    バージョン

    言語

    • C++20

    処理系

    参照