Namensräume
Varianten
Aktionen

std::chrono::operator==,<=>
Von cppreference.com
 
 
 
 
Definiert in Header <chrono>
constexpr bool operator==( const std::chrono::year_month_day& x,
                           const std::chrono::year_month_day& y ) noexcept;
(1) (seit C++20)
constexpr std::strong_ordering

    operator<=>( const std::chrono::year_month_day& x,

                 const std::chrono::year_month_day& y ) noexcept;
(2) (seit C++20)

Vergleicht die beiden `year_month_day`-Werte x und y. Dies ist ein lexikographischer Vergleich: Zuerst wird das year() verglichen, dann das month() und schließlich das day().

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

[edit] Rückgabewert

1) x.year() == y.year() && x.month() == y.month() && x.day() == y.day()
2) Wenn x.year() <=> y.year != 0, dann x.year() <=> y.year; andernfalls, wenn x.month() <=> y.month() != 0, dann x.month() <=> y.month(); andernfalls x.day() <=> y.day().

[edit] Hinweise

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

[edit] 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);
}