std::chrono...nth_day_last(3)
π std::chrono...nth_day_last(3) π
okay so bestie, this is a page from the C++ Standard Library manual, and we're talking about a constructor. specifically std::chrono::year_month_day_last::year_month_day_last β yes the name is a whole mouthful, she's giving "my parents gave me four middle names" energy, but stay with me π«Ά
β¨ NAME β¨
std::chrono::year_month_day_last::year_month_day_last β literally the constructor for std::chrono::year_month_day_last. that's it, that's the whole name, no notes π
πΈ SYNOPSIS πΈ
constexpr year_month_day_last( const std::chrono::year& y,
const std::chrono::month_day_last& mdl
) noexcept;
(since C++20) β she's a modern girl, she did not exist before C++20, periodt β
π¦ NOTES π¦
so what does this cutie actually do? she constructs a year_month_day_last object that stores the year y and the month mdl.month(). and the object she builds represents the last day of that year and month. that's the whole vibe β she's the end-of-month icon, the final boss of the calendar π
also! you can make a year_month_day_last a totally different way: by combining a std::chrono::year_month with std::chrono::last using operator/. two paths, same slay β¨
π EXAMPLE π
// Run this code π
#include <chrono>
#include <iostream>
int main()
{
std::cout << "All last days of months of a given year:\n";
constexpr std::chrono::year year{2021};
for (int i{1}; i <= 12; ++i)
{
const std::chrono::month_day_last mdl{std::chrono::month(i) / std::chrono::last};
const std::chrono::year_month_day_last ymdl{year, mdl};
std::cout << ymdl << " day: " << ymdl.day() << '\n';
}
}
π Possible output
All last days of months of a given year:
2021/Jan/last day: 31
2021/Feb/last day: 28
2021/Mar/last day: 31
2021/Apr/last day: 30
2021/May/last day: 31
2021/Jun/last day: 30
2021/Jul/last day: 31
2021/Aug/last day: 31
2021/Sep/last day: 30
2021/Oct/last day: 31
2021/Nov/last day: 30
2021/Dec/last day: 31
look at February doing her little 28 days thing π she's doing her best okay
π SEE ALSO π
operator/β the conventional syntax for Gregorian calendar date creation, (C++20) (function). yes she's the other way to build these, go say hi π
ngl the double-colon name is lowkey terrifying but she's just a constructor, she doesn't bite π«Ά
and that's the page!! brought to you by cppreference.com, dated 2024.06.10, filed under std::chrono...nth_day_last(3) in the C++ Standard Library section β mwah, go build some dates bestie π
β¨
π¦ 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