• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <chrono>

    std::chrono::operator<=>

    namespace std::chrono {
      constexpr strong_ordering operator<=>(const year_month& x, const year_month& y) noexcept; // (1) C++20
    }
    

    概要

    year_month同士の三方比較を行う。

    戻り値

    • (1) : 以下と等価:

    if (auto c = x.year() <=> y.year(); c != 0) return c;
    return x.month() <=> y.month();
    

    例外

    投げない

    備考

    • この演算子により、operator<operator<=operator>operator>=が使用可能になる

    #include <cassert>
    #include <chrono>
    
    using namespace std::chrono_literals;
    
    int main()
    {
      assert((2020y/3 <=> 2020y/3) == 0);
    
      assert(2020y/2 < 2020y/3);
      assert(2020y/2 <= 2020y/3);
    
      assert(2020y/3 > 2020y/2);
      assert(2020y/3 >= 2020y/2);
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系