# Standard library header <typeindex> (C++11)

> C++ Atlas: `cppatlas.com/w/cpp/header/typeindex` | Source: https://en.cppreference.com/w/cpp/header/typeindex | Domain: Standard headers | Standards: C++11, C++20

This header is part of the type support library.

## Official Specification Summary (cppreference)

This header is part of the type support library.

**Includes**

- `<compare>` (C++20): Three-way comparison operator support

**Classes**

- `type_index` (C++11): wrapper around a `type_info` object, that can be used as index in associative and unordered associative containers (class)
- `std::hash<std::type_index>` (C++11): hash support for `std::type_index` (class template specialization)

**Forward declarations**

Defined in header `<functional>`

- `hash` (C++11): hash function object (class template)

### Synopsis

```cpp
#include <compare>

namespace std {
  class type_index;
  template<class T> struct hash;
  template<> struct hash<type_index>;
}
```

#### Class `std::type_index`

```cpp
namespace std {
  class type_index {
  public:
    type_index(const type_info& rhs) noexcept;
    bool operator==(const type_index& rhs) const noexcept;
    bool operator< (const type_index& rhs) const noexcept;
    bool operator> (const type_index& rhs) const noexcept;
    bool operator<=(const type_index& rhs) const noexcept;
    bool operator>=(const type_index& rhs) const noexcept;
    strong_ordering operator<=>(const type_index& rhs) const noexcept;
    size_t hash_code() const noexcept;
    const char* name() const noexcept;

  private:
    const type_info* target; // exposition only
    // Note that the use of a pointer here, rather than a reference,
    // means that the default copy/move constructor and assignment
    // operators will be provided and work as expected.
  };
}
```

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