std::litera...:operator""d(3)

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

okay so bestie, welcome to the std::litera...:operator""d(3) page from the C++ Standard Libary manual β€” yes, that's the manual name exactly as the header spells it, typo and all, and we are obsessed with the chaos πŸ˜­πŸ’…

🌸 NAME 🌸

std::literals::chrono_literals::operator""d β€” std::literals::chrono_literals::operator""d

(no bestie, you're not seeing double: the NAME section literally repeats it twice. periodt. πŸ‘‘)

✨ Synopsis ✨

Defined in header <chrono>
constexpr std::chrono::day operator ""d( unsigned long long d )
(since C++20)
noexcept;

Forms a std::chrono::day literal representing a day of the month in the calendar. It's (since C++20), so it's giving modern C++ main character energy ✨.

πŸ“₯ Parameters πŸ“₯

  • d β€” the day value. That's it. The whole parameter. Iconic minimalism πŸ’….

πŸ“€ Return value πŸ“€

A std::chrono::day storing d. If d > 255, the stored value is unspecified.

bestie, that's the important caveat: over 255 and the standard is literally like β€œstored value? unspecified, idk her” 😭 so don't act surprised.

πŸ› οΈ Possible implementation πŸ› οΈ

constexpr std::chrono::day operator ""d(unsigned long long d) noexcept
{
    return std::chrono::day(d);
}

πŸ“ Notes πŸ“

This operator is declared in the namespace std::literals::chrono_literals, where both literals and chrono_literals are inline namespaces. Access to this operator can be gained with:

  • using namespace std::literals,
  • using namespace std::chrono_literals, or
  • using namespace std::literals::chrono_literals.

In addition, within the namespace std::chrono, the directive using namespace literals::chrono_literals; is provided by the standard library, so that if a programmer uses using namespace std::chrono; to gain access to the classes in the chrono library, the corresponding literal operators become visible as well. iykyk 🫢

πŸ’» Example πŸ’»

// Run this code

#include <chrono>
#include <iostream>

int main()
{
    using namespace std::literals::chrono_literals;

    std::cout << static_cast<unsigned>(42d) << '\t' << 42d << '\n'
              << static_cast<unsigned>(256d) << '\t' << 256d << '\n' // unspecified
              << static_cast<unsigned>(298d) << '\t' << 298d << '\n';
// unspecified
}

this example ate, no notes πŸ”₯

πŸ–¨οΈ Possible output πŸ–¨οΈ

42      42 is not a valid day
0       00 is not a valid day
42      42 is not a valid day

πŸ‘€ See also πŸ‘€

  • constructor β€” constructs a day (public member function of std::chrono::day)
  • operator unsigned β€” retrieves the stored day value (public member function of std::chrono::day)

okay that's the whole page, bestie. source/version: http://cppreference.com; date: 2024.06.10; and the footer is still out here repeating std::litera...:operator""d(3) πŸ’–βœ¨

πŸ“¦ where this page comes from