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;
}
}
出力
Mon : 1
Tue : 2
Wed : 3
Thu : 4
Fri : 5
Sat : 6
Sun : 7
バージョン
言語
- C++20
処理系
- Clang: 10.0 ✅
- GCC: 9.2 ❌, 15.1 ✅
- Visual C++: 2019 Update 3 ❌