constexpr explicit operator int() const noexcept; // (1) C++20
概要
year
オブジェクトをint
型に明示的に変換する。
戻り値
- (1) : メンバ変数として保持している
int
型としての年の値を返す
例
#include <cassert>
#include <chrono>
namespace chrono = std::chrono;
int main()
{
chrono::year y{2020};
auto value = static_cast<int>(y);
assert(value == 2020);
}
12
#include <cassert>
#include <chrono>
namespace chrono = std::chrono;
int main()
{
chrono::year y{2020};
auto value = static_cast<int>(y);
assert(value == 2020);
}
出力
バージョン
言語
- C++20
処理系
- Clang: 8.0 ✅
- GCC: 9.2 ❌
- Visual C++: 2019 Update 3 ❌