std::chrono...kday::month,(3)
β¨ NAME β¨
hey bestie π welcome to the std::chrono...kday::month,(3) page from the C++ Standard Libary manual (and yeah, the header literally spells it βLibaryβ β weβre keeping that energy π). this page is all about the accessors on std::chrono::year_month_weekday, and the title is a little chaotic but we move π«Ά.
the NAME section is exactly this string, no edits, no cap:
std::chrono::year_month_weekday::year,std::chrono::year_month_weekday::month, - std::chrono::year_month_weekday::year,std::chrono::year_month_weekday::month,
so yeah β it lists year and month and then repeats itself. iconic behavior, honestly π
.
πΈ Synopsis πΈ
okay so the synopsis starts with this floating line, and we are not gonna question it:
std::chrono::year_month_weekday::weekday_indexed
then it hits you with five constexpr / noexcept accessors, all since C++20 β¨. hereβs the synopsis exactly as it appears (formatting chaos included, because we respect the lore π):
constexpr std::chrono::year year() const noexcept;
(1) (since C++20)
constexpr std::chrono::month month() const noexcept;
(2) (since C++20)
constexpr std::chrono::weekday weekday() const noexcept;
(3) (since C++20)
constexpr unsigned index() const noexcept;
(4) (since C++20)
constexpr std::chrono::weekday_indexed weekday_indexed() const
(5) (since C++20)
noexcept;
so thatβs:
- (1)
constexpr std::chrono::year year() const noexcept;since C++20 - (2)
constexpr std::chrono::month month() const noexcept;since C++20 - (3)
constexpr std::chrono::weekday weekday() const noexcept;since C++20 - (4)
constexpr unsigned index() const noexcept;since C++20 - (5)
constexpr std::chrono::weekday_indexed weekday_indexed() const noexcept;since C++20
they all retrieve the field values stored in your year_month_weekday object. simple, clean, slay π
.
π Return value π
hereβs what each one hands back to you, bestie:
- returns the stored
std::chrono::yearvalue π - returns the stored
std::chrono::monthvalue πΈ - returns the stored
std::chrono::weekdayvalue π¦ - returns the stored weekday index π’
- returns
weekday()[index()]β literally that expression, no cap π
π Example π
the example starts with the classic // Run this code and then this whole little main character moment:
#include <cassert>
#include <chrono>
int main()
{
constexpr auto ym{std::chrono::year(2021)/std::chrono::January};
constexpr auto wdi{std::chrono::Wednesday[1]};
auto ymwdi{ym/wdi};
const auto index{ymwdi.index() + 1};
auto weekday{ymwdi.weekday() + std::chrono::days(1)};
ymwdi = {ymwdi.year()/ymwdi.month()/weekday[index]};
// Second Thursday in January, 2021
assert(std::chrono::year_month_day{ymwdi} ==
std::chrono::January/14/2021);
}
it builds a year_month_weekday, does some index + weekday math, and asserts itβs the second Thursday in January 2021 β obsessed πβ¨.
source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::chrono...kday::month,(3) β mwah πβ¨
π¦ 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