[type.index]

# 17 Language support library [[support]](./#support)

## 17.7 Type identification [[support.rtti]](support.rtti#type.index)

### 17.7.7 Class type_index [type.index]

[ð](#lib:type_index)

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.};}

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3494)

The class type_index provides a simple wrapper fortype_info which can be used as an index type in associative
containers ([[associative]](associative "23.4 Associative containers")) and in unordered associative
containers ([[unord]](unord "23.5 Unordered associative containers"))[.](#1.sentence-1)

[ð](#lib:type_index,constructor)

`type_index(const type_info& rhs) noexcept;
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3506)

*Effects*: Constructs a type_index object, the equivalent of target = &rhs[.](#2.sentence-1)

[ð](#lib:operator==,type_index)

`bool operator==(const type_index& rhs) const noexcept;
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3517)

*Returns*: *target == *rhs.target[.](#3.sentence-1)

[ð](#lib:operator%3c,type_index)

`bool operator<(const type_index& rhs) const noexcept;
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3528)

*Returns*: target->before(*rhs.target)[.](#4.sentence-1)

[ð](#lib:operator%3e,type_index)

`bool operator>(const type_index& rhs) const noexcept;
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3539)

*Returns*: rhs.target->before(*target)[.](#5.sentence-1)

[ð](#lib:operator%3c=,type_index)

`bool operator<=(const type_index& rhs) const noexcept;
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3550)

*Returns*: !rhs.target->before(*target)[.](#6.sentence-1)

[ð](#lib:operator%3e=,type_index)

`bool operator>=(const type_index& rhs) const noexcept;
`

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3561)

*Returns*: !target->before(*rhs.target)[.](#7.sentence-1)

[ð](#lib:operator%3c=%3e,type_index)

`strong_ordering operator<=>(const type_index& rhs) const noexcept;
`

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3572)

*Effects*: Equivalent to:if (*target == *rhs.target) return strong_ordering::equal;if (target->before(*rhs.target)) return strong_ordering::less;return strong_ordering::greater;

[ð](#lib:hash_code,type_index)

`size_t hash_code() const noexcept;
`

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3588)

*Returns*: target->hash_code()[.](#9.sentence-1)

[ð](#lib:name,type_index)

`const char* name() const noexcept;
`

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3599)

*Returns*: target->name()[.](#10.sentence-1)

[ð](#lib:hash,type_index)

`template<> struct hash<type_index>;
`

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/support.tex#L3610)

For an object index of type type_index,hash<type_index>()(index) shall evaluate to the same result as index.hash_code()[.](#11.sentence-1)
