# std::type_info::before

> C++ Atlas: `cppatlas.com/w/cpp/types/type_info/before` | Source: https://en.cppreference.com/w/cpp/types/type_info/before | Domain: Type support | Standards: C++11, C++20

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.

## Official Specification Summary (cppreference)

```cpp
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.

### Parameters

- `rhs` - another type information object to compare to

### Return value

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

### Example

```cpp
#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:

```text
char goes before int in this implementation.
```

### See also

- [`operator==`](https://en.cppreference.com/w/cpp/types/type_info/operator_cmp), [`operator!=`](https://en.cppreference.com/w/cpp/types/type_info/operator_cmp) (removed in C++20): checks whether the objects refer to the same type (public member function)

---
Attribution: content from https://en.cppreference.com/w/cpp/types/type_info/before (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.