• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <typeindex>

    std::type_index::operator<=>

    strong_ordering operator<=>(const type_index& rhs) const noexcept; // (1) C++20
    

    概要

    三方比較を行う

    効果

    type_indexのメンバ変数として保持されているtype_infoオブジェクトへのポインタtargetがあるとして、以下と等価:

    if (*target == *rhs.target) return strong_ordering::equal;
    if (target->before(*rhs.target)) return strong_ordering::less;
    return strong_ordering::greater;
    

    例外

    投げない

    #include <cassert>
    #include <typeindex>
    
    int main()
    {
      std::type_index t1 = typeid(int);
      std::type_index t2 = typeid(int);
      std::type_index t3 = typeid(double);
    
      assert((t1 <=> t2) == 0);
      assert((t1 <=> typeid(int)) == 0);
      assert((t1 <=> t3) != 0);
      assert((t1 <=> typeid(double)) != 0);
    }
    

    出力

    バージョン

    言語

    • C++20

    処理系

    参照