std::chrono...hrono::year)(3)

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

πŸ’– NAME πŸ’–

hey bestie!! welcome to the std::chrono::operator==,(std::chrono::year) page πŸ’– this one lives in the C++ Standard Libary manual (yes, that's the exact spelling in the header β€” we respect the source, no cap πŸ’…), and the header title is literally std::chrono...hrono::year)(3).

The NAME line, in all its duplicated glory: std::chrono::operator==,(std::chrono::year) β€” std::chrono::operator==,(std::chrono::year).

so yeah, the page is about std::chrono::operator==,(std::chrono::year), and the source says the name twice. iconic behavior. periodt. ✨

πŸŽ€ Synopsis πŸŽ€

Defined in header <chrono>. πŸ’–

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

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

okay so this literally compares the two std::chrono::year values x and y. that's the whole task. πŸ¦‹

The <, <=, >, >=, and != operators are synthesized from operator<=> and operator== respectively. (iykyk: the comparison squad comes built in. ✨)

🌸 Return value 🌸

  1. int(x) == int(y)
  2. int(x) <=> int(y)

fr fr, overload (1) hands you int(x) == int(y), and overload (2) hands you int(x) <=> int(y). simple, slay, done. πŸ’…

πŸ¦‹ Example πŸ¦‹

// Run this code

#include <chrono>
#include <iostream>

int main()
{
    using namespace std::chrono;

    constexpr year y1{2020};
    constexpr year y2{2021};

    std::cout << std::boolalpha << (y1 != y2) << '\n';

    static_assert((2020y < 2023y) && (2020y == 2020y) && (2020y <= 2023y) &&
                  (2023y > 2020y) && (2023y != 2020y) && (2023y >= 2020y));
}

⭐ Output ⭐

true

πŸ’– source: http://cppreference.com Β· version/date: 2024.06.10 Β· footer title: std::chrono...hrono::year)(3) β€” bye bestie, go compare those years and slay! πŸŽ€βœ¨πŸ’…

πŸ“¦ where this page comes from