Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |chrono‎ |year month day
       
       
      Date and time library
       
       
      Defined in header<chrono>
      constexprbool operator==(conststd::chrono::year_month_day& x,
                                 conststd::chrono::year_month_day& y)noexcept;
      (1)(since C++20)
      constexprstd::strong_ordering

          operator<=>(conststd::chrono::year_month_day& x,

                       conststd::chrono::year_month_day& y)noexcept;
      (2)(since C++20)

      Compares the twoyear_month_day valuesx andy. This is a lexicographical comparison: theyear() is compared first, thenmonth(), thenday().

      The<,<=,>,>=, and!= operators aresynthesized fromoperator<=> andoperator== respectively.

      [edit]Return value

      1)x.year()== y.year()&& x.month()== y.month()&& x.day()== y.day()
      2) Ifx.year()<=> y.year!=0,x.year()<=> y.year; otherwise ifx.month()<=> y.month()!=0,x.month()<=> y.month(); otherwisex.day()<=> y.day().

      [edit]Notes

      If bothx andy represent valid dates (x.ok()&& y.ok()==true), the result of the lexicographical comparison is consistent with the calendar order.

      [edit]Example

      Run this code
      #include <chrono> int main(){constexprauto ymd1{std::chrono::day(13)/7/1337};constexprauto ymd2{std::chrono::year(1337)/7/13};    static_assert(ymd1== ymd2);    static_assert(ymd1<= ymd2);    static_assert(ymd1>= ymd2);    static_assert(ymd1<=> ymd2==0);}
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/year_month_day/operator_cmp&oldid=157569"

      [8]ページ先頭

      ©2009-2026 Movatter.jp