Namespaces
Variants
Views
Actions

std::type_info::before

From cppreference.com
< cpp‎ | types‎ | type info
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (C++20)
Dynamic memory management
Program utilities
Coroutine support (C++20)
Variadic functions
Debugging support
(C++26)
Three-way comparison
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Date and time
Function objects
Formatting library (C++20)
(C++11)
Relational operators (deprecated in C++20)
Integer comparison functions
(C++20)(C++20)(C++20)   
(C++20)
Swap and type operations
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
Common vocabulary types
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)
Elementary string conversions
(C++17)
(C++17)

 
 
 
bool before( const type_info& rhs ) const;
(until C++11)
bool before( const type_info& rhs ) const noexcept;
(since C++11)

Returns true if the type of this type_info precedes the type of rhs in the implementation's collation order. No guarantees are given; in particular, the collation order can change between the invocations of the same program.

Contents

[edit] Parameters

rhs - another type information object to compare to

[edit] Return value

true if the type of this type_info precedes the type of rhs in the implementation's collation order.

[edit] Example

#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";
}

Possible output:

char goes before int in this implementation.

[edit] See also

(removed in C++20)
checks whether the objects refer to the same type
(public member function) [edit]