Namespaces
Variants

std::type_info:: before

From cppreference.net
Utilities library
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 goes before char in this implementation.\n";
    else
        std::cout << "char goes before int in this implementation.\n";
}

可能的输出:

char goes before int in this implementation.

参见

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