std::chrono::year:: year
From cppreference.net
C++
Date and time library
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::chrono::year
| Member functions | ||||
|
year::year
|
||||
| Nonmember functions | ||||
| Helper classes | ||||
|
(C++26)
|
|
year
(
)
=
default
;
|
(1) | (C++20以降) |
|
constexpr
explicit
year
(
int
y
)
noexcept
;
|
(2) | (C++20以降) |
year
オブジェクトを構築します。
1)
デフォルトコンストラクタは年値が初期化されないまま残します。
2)
y
が範囲
[
-
32767
,
32767
]
内にある場合、
year
オブジェクトを構築し、年値
y
を保持します。それ以外の場合、保持される値は未規定です。
例
このコードを実行
#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].