std::type_info::before_C++中文网

bool before( const type_info& rhs ) const;

(C++11 前)

bool before( const type_info& rhs ) const noexcept;

(C++11 起)

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

参数

返回值

若此 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.

参阅