std::chrono...chrono::day)(3)
π NAME π
okay so this is the manual page for std::chrono::operator<<(std::chrono::day) β the page title doodle is std::chrono...chrono::day)(3), and it lives in the C++ Standard Libary manual (spelling is theirs, not mine π). The NAME line is literally std::chrono::operator<<(std::chrono::day) - and then it says std::chrono::operator<<(std::chrono::day) again. Repetition? Iconic. We stan a consistent name. π
πΈ Synopsis πΈ
Defined in header <chrono>:
template< class CharT, class Traits >
std::basic_ostream<CharT, Traits>&
operator<<( std::basic_ostream<CharT, Traits>& os, const std::chrono::day& d );
This overload is (since C++20), bestie. β¨
So what does it do? It forms a std::basic_string<CharT> s consisting of the day value stored in d, formatted as a decimal number, with a leading zero if the result would otherwise be a single decimal digit. Then, if !d.ok(), it appends the string " is not a valid day" β yes, with that leading space β to the formatted string. Finally, it inserts that string into os. Slay. π
Equivalent to:
return os << (d.ok() ?
std::format(STATICALLY_WIDEN<CharT>("{:%d}"), d) :
std::format(STATICALLY_WIDEN<CharT>("{:%d} is not a valid day"), d));
where STATICALLY_WIDEN<CharT>("...") is "..." if CharT is char, and L"..." if CharT is wchar_t. π«Ά
π Return value π
It returns os. That's the whole return value. No cap. π
π Example π
// Run this code
#include <chrono>
#include <iostream>
int main()
{
constexpr std::chrono::day d1{31}, d2{7}, d3{42}, d4{};
std::cout << d1 << '\n'
<< d2 << '\n'
<< d3 << '\n'
<< d4 << '\n';
}
Possible output, bestie:
31
07
42 is not a valid day
00 is not a valid day
π¦ See also π¦
format(C++20)β stores formatted representation of the arguments in a new string (function template).std::formatter<std::chrono::day>(C++20)β formatting support forday(class template specialization).
made with π by your Unix bestie, sourced from http://cppreference.com, dated 2024.06.10. π
π¦ 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