Namespaces
Variants

std::type_index::operator==,!=,<,<=,>,>=,<=>

来自 zh.cppreference.net
 
 
 
类型支持
基本类型
定宽整数类型 (C++11)
定宽浮点类型 (C++23)
(C++11)    
(C++17)
数值极限
C 数值极限接口
运行时类型信息
 
 
bool operator==( const type_index& rhs ) const noexcept;
(1) (C++11 起)
bool operator!=( const type_index& rhs ) const noexcept;
(2) (C++11 起)
(C++20 前)
bool operator<( const type_index& rhs ) const noexcept;
(3) (C++11 起)
bool operator<=( const type_index& rhs ) const noexcept;
(4) (C++11 起)
bool operator>( const type_index& rhs ) const noexcept;
(5) (C++11 起)
bool operator>=( const type_index& rhs ) const noexcept;
(6) (C++11 起)
std::strong_ordering operator<=>( const type_index& rhs ) const noexcept;
(7) (C++20 起)

比较底层的 std::type_info 对象。

1,2) 检查底层的 std::type_info 对象是否指向同一类型。
3-7) 按实现定义的顺序比较底层的 std::type_info 对象。该比较通过 type_info::before 进行。

!= 运算符由 合成自 operator==。

(C++20 起)

参数

rhs - 用于比较的另一个 type_index 对象

返回值

1) true 若底层 std::type_info 对象指向相同类型,否则为 false 。
2) true 若底层 std::type_info 对象指向的不是相同类型,否则为 false 。
3-6) true 若底层 std::type_info 对象所引用的类型按对应顺序排列,否则为 false 。
7) std :: strong_ordering :: equal 若底层 std::type_info 对象指向相同类型,否则为 std :: strong_ordering :: less 若 * this 的底层 std::type_info 对象在实现定义的排序中先于 rhs 的底层对象,否则为 std :: strong_ordering :: greater 。