• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <chrono>

    std::chrono::weekday::iso_encoding

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

    概要

    weekdayオブジェクトが保持する曜日の値を、ISO 8601の仕様に基づき、月曜日から日曜日までを値の範囲[1, 7]として取得する。

    戻り値

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

    return wd == 0u ? 7u : wd;
    

    例外

    投げない

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

    出力

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

    バージョン

    言語

    • C++20

    処理系

    参照