• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function template
    <functional>

    std::reference_wrapper::operator<=>

    friend constexpr synth-three-way-result<T>
      operator<=>(reference_wrapper x,
                  reference_wrapper y);          // (1) C++26
    
    friend constexpr synth-three-way-result<T>
      operator<=>(reference_wrapper x,
                  const T& y);                   // (2) C++26
    
    friend constexpr synth-three-way-result<T>
      operator<=>(reference_wrapper x,
                  reference_wrapper<const T> y); // (3) C++26
    

    概要

    三方比較を行う。

    • (1) : 同じ要素型のreference_wrapper同士を三方比較する
    • (2) : reference_wrapperと要素型Tを三方比較する
    • (3) : reference_wrapper<T>reference_wrapper<const T>を三方比較する

    (2)と(3)はオペランドを左右で逆にしても使用できる。

    テンプレートパラメータ制約

    戻り値

    備考

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

    #include <cassert>
    #include <compare>
    #include <functional>
    
    int main()
    {
      int x = 3;
      int y = 3;
      int z = 4;
    
      assert((std::ref(x) <=> std::ref(y)) == 0);
      assert(std::ref(x) < std::ref(z));
      assert(std::ref(x) <= std::ref(z));
      assert(std::ref(z) > std::ref(x));
      assert(std::ref(z) >= std::ref(x));
    
      assert((std::ref(x) <=> 3) == 0);
      assert((3 <=> std::ref(x)) == 0);
    
      assert((std::ref(x) <=> std::cref(y)) == 0);
      assert((std::cref(x) <=> std::ref(y)) == 0);
    }
    

    出力

    バージョン

    言語

    • C++26

    処理系

    参照