Namespaces
Variants

std::chrono:: operator==,<=> (std::chrono::year_month_day)

From cppreference.net
Definiert im Header <chrono>
constexpr bool operator == ( const std:: chrono :: year_month_day & x,
const std:: chrono :: year_month_day & y ) noexcept ;
(1) (seit C++20)
(2) (seit C++20)

Vergleicht die beiden year_month_day -Werte x und y . Dies ist ein lexikografischer Vergleich: zuerst wird year() verglichen, dann month() , dann day() .

Die < -, <= -, > -, >= - und != -Operatoren werden synthetisiert aus operator <=> beziehungsweise operator == .

Rückgabewert

1) x. year ( ) == y. year ( ) && x. month ( ) == y. month ( ) && x. day ( ) == y. day ( )
2) Falls x. year ( ) <=> y. year ! = 0 , x. year ( ) <=> y. year ; andernfalls falls x. month ( ) <=> y. month ( ) ! = 0 , x. month ( ) <=> y. month ( ) ; andernfalls x. day ( ) <=> y. day ( ) .

Hinweise

Wenn sowohl x als auch y gültige Daten darstellen ( x. ok ( ) && y. ok ( ) == true ), stimmt das Ergebnis des lexikographischen Vergleichs mit der Kalenderreihenfolge überein.

Beispiel

#include <chrono>
int main()
{
    constexpr auto ymd1{std::chrono::day(13)/7/1337};
    constexpr auto ymd2{std::chrono::year(1337)/7/13};
    static_assert(ymd1 == ymd2);
    static_assert(ymd1 <= ymd2);
    static_assert(ymd1 >= ymd2);
    static_assert(ymd1 <=> ymd2 == 0);
}