<typeindex>


[added with C++11]


Include the standard header <typeindex> to define a class and function that support indexing of objects of class type_info.

namespace std {
class type_index;
class hash;
}  // namespace std

hash

template<>
    struct hash<type_index>
        : public unary_function<type_index, size_t>
    { // hashes a typeinfo object
    size_t operator()(type_index val) const;
    };

The template class defines its member function as returning val.hash_code(). The member function defines a hash function, suitable for mapping values of type type_index to a distribution of index values.

type_index

class type_index
    { // indexes a typeinfo object
public:
    type_index(const type_info& tinfo) noexcept;

    const char *name() const;
    size_t hash_code() const;

    bool operator==(const type_info& right) const noexcept;
    bool operator!=(const type_info& right) const noexcept;
    bool operator<(const type_info& right) const noexcept;
    bool operator>=(const type_info& right) const noexcept;
    bool operator>(const type_info& right) const noexcept;
    bool operator<=(const type_info& right) const noexcept;

private:
    type_info *ptr; // exposition only
    };

The class wraps a pointer to type_info to assist in indexing by such objects.

type_index::hash_code

size_t hash_code() const;

The member function returns ptr->hash_code().

type_index::name

const char *name() const;

The member function returns ptr->name().

type_index::operator<

bool operator<(const type_index& right) const noexcept;

The member operator returns *ptr->before(*right.ptr).

type_index::operator<=

bool operator<=(const type_index& right) const noexcept;

The member operator returns !(right < *this).

type_index::operator!=

bool operator!=(const type_index& right) const noexcept;

The member operator returns !(*this == right).

type_index::operator==

bool operator==(const type_index& right) const noexcept;

The member operator returns *ptr == right.ptr.

type_index::operator>

bool operator>(const type_index& right) const noexcept;

The member operator returns right < *this.

type_index::operator>=

bool operator>=(const type_index& right) const noexcept;

The member operator returns !(*this < right).

type_index::type_index

type_index(const type_info& tinfo) noexcept;

The constructor initializes ptr to &tinfo.


See also the Table of Contents and the Index.

Copyright © 1992-2013 by P.J. Plauger. All rights reserved.