• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <compare>

    std::strong_ordering::operator!=

    //operator==により、以下のオーバーロードが使用可能になる        
    friend constexpr bool operator!=(strong_ordering v, strong_ordering w) noexcept; // (1)
    
    friend constexpr bool operator!=(strong_ordering v, /*unspecified*/) noexcept;   // (2)
    
    friend constexpr bool operator!=(/*unspecified*/, strong_ordering v) noexcept;   // (3)
    

    概要

    • (1) : strong_ordering同士の非等値比較を行う
    • (2)(3) : strong_orderingの値がstrong_ordering::equalで無いことを調べる。

    戻り値

    • (1) : return !(v == w)
    • (2)(3) : return !(v == 0)

    例外

    投げない。

    備考

    これらの演算子は全てoperator==によって使用可能になる。

    unspecifiedとなっている片側の引数には0リテラルのみが使用できる。それ以外の物を渡した場合、動作は未定義

    #include <iostream>
    #include <compare>
    
    int main()
    {
      std::strong_ordering comp1 = 1 <=> 1;
      std::strong_ordering comp2 = 2 <=> 1;
    
      std::cout << std::boolalpha;
    
      // (1)
      std::cout << (comp1 != comp2) << std::endl;
    
      // (2) 
      std::cout << (comp1 != 0) << std::endl;
    
      // (3)
      std::cout << (0 != comp1) << std::endl;
    }
    

    出力

    true
    false
    false
    

    バージョン

    言語

    • C++20

    処理系

    • Clang: 8.0(1が未実装)
    • GCC: 10.1(full support)
    • Visual C++: 2019(1が未実装)

    関連項目

    参照