std::chrono...hrono::year)(3)
π 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 πΈ
int(x) == int(y)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
- 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