Namespaces
Variants

std::type_info::before

来自 zh.cppreference.net
 
 
 
类型支持
基本类型
定宽整数类型 (C++11)
定宽浮点类型 (C++23)
(C++11)    
(C++17)
数值极限
C 数值极限接口
运行时类型信息
 
 
bool before( const type_info& rhs ) const;
(C++11 起 noexcept)

如果 this 的类型 true 在实现定义的排列顺序中位于 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 中移除)
检查对象是否引用相同类型
(公开成员函数)