std::type_info::before

< cpp‎ | types‎ | type info
bool before( const type_info& rhs ) const;
(C++11 起为 noexcept)

若此 type_info 的类型在实现的对照顺序中列于 rhs 的类型之前则返回 true。不给出保证,特别是对照顺序可以在同一程序的调用之间改变。

参数

rhs - 要比较的另一个类型信息对象

返回值

若此 type_info 的类型在实现的对照顺序中列于 rhs 的类型之前则为 true

示例

#include <iostream>
#include <typeinfo>
 
int main()
{
    if(typeid(int).before(typeid(char)))
        std::cout << "此实现中 int 在 char 之前。\n";
    else
        std::cout << "此实现中 char 在 int 之前。\n";
}

可能的输出:

此实现中 char 在 int 之前。

参阅

(C++20 中移除)
检查对象是否指代相同类型
(公开成员函数)