• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <compare>

    std::strong_ordering::operator>=

    friend constexpr bool operator>=(strong_ordering v, /*unspecified*/) noexcept;   // (1)
    
    friend constexpr bool operator>=(/*unspecified*/, strong_ordering v) noexcept;   // (2)
    

    概要

    • (1) : strong_orderingの値がstrong_ordering::greaterもしくはequalであるかを調べる。
    • (2) : strong_orderingの値がstrong_ordering::lessもしくはequalであるかを調べる。

    戻り値

    int型のメンバ変数valueに各有効値に対応する値を保持しているとして、以下と等価

    • (1) : return v.value >= 0
    • (2) : return 0 >= v.value

    例外

    投げない。

    備考

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

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

    出力

    false
    true
    true
    true
    

    バージョン

    言語

    • C++20

    処理系

    関連項目

    参照