std::chrono::year::year(3)
πΈ NAME πΈ
okay so we're on std::chrono::year::year β that's the constructor page for std::chrono::year::year, from the C++ Standard Libary manual (spelled exactly like that up top, no cap π). This is your bestie's guide to making a year object, and it's lowkey iconic.
β¨ SYNOPSIS β¨
year() = default; (1) (since C++20)
constexpr explicit year( int y ) noexcept; (2) (since C++20)
Constructs a year object. That's the whole assignment, bestie π
.
π what each constructor is giving π
year() = default;β constructor (1), since C++20. The default constructor leaves the year value uninitialized. Like, it does not set a value for you; uninitialized is the whole mood. Don't act surprised, bestie π.constexpr explicit year( int y ) noexcept;β constructor (2), since C++20. Ifyis in the range[-32767, 32767], it constructs ayearobject holding the year valuey. Ifyis outside that range, the value held is unspecified. No cap.
ifyis outside[-32767, 32767], the value held is unspecified β lowkey do not rely on it, bestie π
π EXAMPLE π
Run this code, bestie β it's giving "use constructor (2) in a lambda and count leap years" energy π¦β¨:
#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";
}
π OUTPUT π
There are 15891 leap years in the range [-32767, 32767].
source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::chrono::year::year(3) β byeee bestie, go construct some years and slay β¨π
π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms