• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <compare>

    std::strong_ordering::operator weak_ordering

    constexpr operator weak_ordering() const noexcept;
    

    概要

    std::weak_ordering型に変換する。

    戻り値

    以下と等価:

    return *this == 0 ? weak_ordering::equivalent :
           *this <  0 ? weak_ordering::less :
                        weak_ordering::greater;
    

    例外

    投げない

    #include <iostream>
    #include <compare>
    
    int main()
    {
      std::strong_ordering strong = 1 <=> 2;
      std::weak_ordering weak = strong;
    
      std::cout << std::boolalpha;
      std::cout << (weak == 0) << std::endl;
      std::cout << (weak != 0) << std::endl;
      std::cout << (weak <  0) << std::endl;
      std::cout << (weak <= 0) << std::endl;
      std::cout << (weak >  0) << std::endl;
      std::cout << (weak >= 0) << std::endl;
    }
    

    出力

    false
    true
    true
    true
    false
    false
    

    バージョン

    言語

    • C++20

    処理系

    参照