std::chrono...no::weekday)(3)
πΈ NAME πΈ
std::chrono::operator<<(std::chrono::weekday) β okay so this is the lil overload that lets you just stream a weekday straight into an output stream, bestie. That's it. That's the whole vibe. π
This page lives in the C++ Standard Library manual, section 3 (library functions), iykyk.
β¨ Synopsis β¨
First things first, she's defined in header <chrono> π
template< class CharT, class Traits >
std::basic_ostream<CharT, Traits>&
(since C++20) β
operator<<( std::basic_ostream<CharT, Traits>& os, const std::chrono::weekday& wd );
So like, here's the tea on what she actually does β:
- If
!wd.ok(), she insertswd.c_encoding()followed by" is not a valid weekday"intoos. Basically she's calling out your invalid weekday in front of everyone π - Otherwise, she forms a
std::basic_string<CharT>namedsconsisting of the abbreviated weekday name for the weekday represented bywd, determined using the locale associated withos, and insertssintoos. Slay π
And she's equivalent to this whole thing:
return os << (wd.ok() ?
std::format(os.getloc(), STATICALLY_WIDEN<CharT>("{:L%a}"), wd) :
std::format(os.getloc(), STATICALLY_WIDEN<CharT>("{} is not a valid weekday"),
wd.c_encoding()));
Where STATICALLY_WIDEN<CharT>("...") is "..." if CharT is char, and L"..." if CharT is wchar_t. Little type-dependent glow-up, we love to see it π
π¦ Return value π¦
She returns os. That's it. Same stream you handed her, bestie β she just decorated it π
π Example π
This section is incomplete π Reason: no example
Yeahβ¦ no example. Not me showing up to the group chat with nothing to demo π (There's literally a category tag for it down below, see? Called out in the official record.)
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. (Retroactive glow-ups, honestly iconic β¨)
P2372R3β applied to C++20- Behavior as published: the given locale was used by default
- Correct behavior:
Lis needed to use the given locale
Periodt. That's the whole fix π«Ά
π₯ See also π₯
format(C++20) β function template β stores formatted representation of the arguments in a new string πstd::formatter<std::chrono::weekday>(C++20) β class template specialization β formatting support for weekday β
πΈ Category πΈ
Todono exampleβ yeah she's flagged, someone please come write her a demo π
Source/version and date, per the footer: this one's straight from http://cppreference.com, dated 2024.06.10 β so go touch some grass, hydrate, and remember: abbreviated weekday names only, no cap ππ§ββοΈ
π¦ 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