std::chrono::year::year
From cppreference.com
| year() = default; |
(1) | (C++20以降) |
| constexpr explicit year( int y ) noexcept; |
(2) | (C++20以降) |
year オブジェクトを構築します。
1) デフォルトコンストラクタは、年の値を初期化せずに残します。
2) y が範囲
[-32767, 32767] にある場合、年の値 y を保持する year オブジェクトを構築します。それ以外の場合、保持される値は未指定です。[編集] 例
このコードを実行
#include <chrono> #include <iostream> int main() { using namespace std::chrono; constexpr int leap_years = [] { int count{}; for (int i{year::min()}; i <= int{year::max()}; ++i) if (year{i}.is_leap()) // uses constructor (2) ++count; return count; } (); static_assert(15891 == leap_years); std::cout << "There are " << leap_years << " leap years in the range [" << int(year::min()) << ", " << int(year::max()) << "].\n"; }
出力
There are 15891 leap years in the range [-32767, 32767].