std::chrono...:month_day)(3)

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

πŸ’… std::chrono::operator==,(std::chrono::month_day) πŸ’…

okay so bestie, this page is from the C++ Standard Libary manual (yes, that’s the manual name, typo and all πŸ’–). It’s the whole glow-up for comparing std::chrono::month_day values. Two month_days walk into a compiler, and this operator tells you if they’re matching. Iconic behavior, no cap ✨.

🌸 NAME 🌸

  • std::chrono::operator==,(std::chrono::month_day) β€” std::chrono::operator==,(std::chrono::month_day)

πŸŒ€ Synopsis πŸŒ€

Defined in header <chrono>:

constexpr bool operator==( const std::chrono::month_day& x,
                           const std::chrono::month_day& y )
    noexcept;                          (1) (since C++20)

constexpr std::strong_ordering operator<=>( const std::chrono::month_day& x,
                                            const std::chrono::month_day& y ) noexcept;
                                       (2) (since C++20)

Compares two month_day values. That’s the whole assignment, and it ate πŸ’….

The <, <=, >, >=, and != operators are synthesized from operator<=> and operator== respectively. Periodt. πŸŽ€

πŸŽ€ Return value πŸŽ€

  1. x.month() == y.month() && x.day() == y.day()
  2. x.month() <=> y.month() != 0 ? x.month() <=> y.month() : x.day() <=> y.day()

πŸ¦‹ Example πŸ¦‹

// Run this code

#include <chrono>
#include <iostream>

int main()
{
    constexpr auto md1{std::chrono::August/15};
    constexpr auto md2{std::chrono::month(8)/std::chrono::day(15)};
    std::cout << std::boolalpha << (md1 == md2) << '\n';

    static_assert(md1 <= md2);
}

Output:

true

source shoutout at the very end: this came from http://cppreference.com, version/date 2024.06.10, page std::chrono...:month_day)(3). Byeee, go compare your month-days responsibly πŸ«ΆπŸ’œ

πŸ“¦ where this page comes from