std::chrono...day::weekday(3)
π NAME π
std::chrono::weekday::weekday β literally std::chrono::weekday::weekday, bestie. This is the std::chrono...day::weekday(3) page from the C++ Standard Libary manual (yes, that exact spelling is on the page, don't come for me π).
β¨ Synopsis β¨
weekday() = default;
(1) (since C++20)
constexpr explicit weekday( unsigned wd ) noexcept;
(2) (since C++20)
constexpr weekday( const std::chrono::sys_days& sd ) noexcept;
(3) (since C++20)
constexpr explicit weekday( const std::chrono::local_days& ld )
(4) (since C++20)
noexcept;
Okay so overload (4)'s declaration gets split around the (4) (since C++20) line in the original, so I kept that energy exact β no editing the source, periodt π
.
π Parameters π
wdβ a weekday value.sdβ a system days object.ldβ a local days object.
π¦ Description π¦
These constructors do one main-character job: construct a weekday object.
- (1)
weekday() = default;β since C++20. The default constructor leaves the weekday value uninitialized. No cap, it just does not initialize it. - (2)
constexpr explicit weekday( unsigned wd ) noexcept;β since C++20. Constructs aweekdayobject holding the weekday valuewd. Ifwd == 7, the value held is0. Ifwd > 255, the value held is unspecified. - (3)
constexpr weekday( const std::chrono::sys_days& sd ) noexcept;β since C++20. Constructs aweekdayobject representing the day of the weeksdcorresponds to. This constructor defines an implicit conversion fromstd::chrono::sys_daystoweekday. - (4) the
const std::chrono::local_days& ldoverload β since C++20. Constructs aweekdayobject representing the day of the weekldcorresponds to, as if byweekday(std::chrono::sys_days(ld.time_since_epoch())).
π¨ Bestie, overload (1) leaves the weekday value uninitialized β that's the vibe check, and it is not giving initialized.
π¦ Example π¦
// Run this code
#include <chrono>
#include <iomanip>
#include <iostream>
int main()
{
constexpr std::chrono::weekday friday{5}; // uses overload (2)
static_assert(friday == std::chrono::Friday);
for (int y{2020}; y <= 2023; ++y)
{
const std::chrono::year cur_year{y};
for (int cur_month{1}; cur_month != 13; ++cur_month)
{
const std::chrono::year_month_day
ymd{cur_year/cur_month/13};
const std::chrono::weekday
cur_weekday{std::chrono::sys_days(ymd)}; // (3)
if (cur_weekday == friday)
std::cout << ymd << " is " << friday << '\n';
}
}
}
π Output π
Output:
2020-03-13 is Fri
2020-11-13 is Fri
2021-08-13 is Fri
2022-05-13 is Fri
2023-01-13 is Fri
2023-10-13 is Fri
π This cutie came from http://cppreference.com, dated 2024.06.10, and it's the std::chrono...day::weekday(3) page. 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