• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <chrono>

    std::chrono::operator==

    namespace std::chrono {
      constexpr bool operator==(const leap_second& x,
                                const leap_second& y) noexcept;        // (1) C++20
    
      template <class Duration>
      constexpr bool operator==(const leap_second& x,
                                const sys_time<Duration>& y) noexcept; // (2) C++20
    }
    

    概要

    等値比較を行う。

    • (1) : leap_secondオブジェクト同士の等値比較を行う
    • (2) : leap_secondオブジェクトとsys_timeオブジェクトの等値比較を行う

    戻り値

    例外

    投げない

    備考

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

    #include <iostream>
    #include <chrono>
    
    namespace chrono = std::chrono;
    using namespace std::chrono_literals;
    
    // うるう秒が挿入された日かを判定
    bool is_leap_second_day(chrono::year_month_day ymd) {
      for (const chrono::leap_second& x : chrono::get_tzdb().leap_seconds) {
        if (x == ymd) {
          return true;
        }
      }
      return false;
    }
    
    int main()
    {
      if (is_leap_second_day(1972y/7/1)) {
        std::cout << "1972/7/1 is a leap second day" << std::endl;
      }
    }
    

    出力

    1972/7/1 is a leap second day
    

    バージョン

    言語

    • C++20

    処理系