std::chrono::year::year
Von cppreference.com
| year() = default; |
(1) | (seit C++20) |
| constexpr explicit year( int y ) noexcept; |
(2) | (seit C++20) |
Konstruiert ein year-Objekt.
1) Der Standardkonstruktor lässt den Jahreswert uninitialisiert.
2) Wenn y im Bereich
[-32767, 32767] liegt, wird ein year-Objekt konstruiert, das den Jahreswert y enthält. Andernfalls ist der gespeicherte Wert nicht spezifiziert.[edit] Beispiel
Führen Sie diesen Code aus
#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"; }
Ausgabe
There are 15891 leap years in the range [-32767, 32767].