std::chrono...day_indexed)(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ NAME πŸŽ€

okay so this is the std::chrono...day_indexed)(3) page from the C++ Standard Libary manual β€” yes, the manual name is folded in right here near the top like a lil name tag 🫢.

The actual star of the page is std::chrono::operator<<(std::chrono::weekday_indexed) β€” and the descriptor line is literally the same string again: std::chrono::operator<<(std::chrono::weekday_indexed). iconic, no notes πŸ’….

🌸 Synopsis 🌸

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_indexed& wdi );

Yep, that’s the overload β€” and it’s (since C++20), so bestie, this is a newer-standard vibe ✨.

It outputs a textual representation of wdi into the stream os, as if by this exact code:

if (wdi.index() >=1 && wdi.index() <= 5)
    os << std::format(os.getloc(), STATICALLY_WIDEN<CharT>("{:L}[{}]"),
                      wdi.weekday(), wdi.index());
else
    os << std::format(os.getloc(), STATICALLY_WIDEN<CharT>("{:L}[{} is not a valid index]"),
                      wdi.weekday(), wdi.index());

And the little translation note is: where STATICALLY_WIDEN<CharT>("...") is "..." if CharT is char, and L"..." if CharT is wchar_t. slay, that’s the whole magic trick πŸ”₯.

πŸŽ€ Return value πŸŽ€

It returns os. That’s it. The stream comes back to you like a boomerang, bestie πŸͺƒ.

πŸ¦‹ Defect reports πŸ¦‹

okay so these behavior-changing defect reports got applied retroactively to previously published C++ standards β€” the committee said β€œactually, bestie, we need to fix that” 😭:

  • DR P2372R3 β€” Applied to: C++20
    • Behavior as published: the given locale was used by default
    • Correct behavior: L is needed to use the given locale

⭐ See also ⭐

  • format (C++20) β€” stores formatted representation of the arguments in a new string; it’s a function template.
  • std::formatter<std::chrono::weekday> (C++20) β€” formatting support for weekday; it’s a class template specialization.

mwah πŸ’‹ this page came from http://cppreference.com, version/date 2024.06.10, and the footer title is std::chrono...day_indexed)(3). periodt πŸ’…βœ¨

πŸ“¦ where this page comes from