最終更新日時(UTC):
が更新

履歴 編集

class
<typeindex>

std::type_index(C++11)

namespace std {
  class type_index;
}

概要

type_indexは、type_infoを連想コンテナや非順序連想コンテナのインデックス型として使用するためのクラスである。

メンバ関数

名前 説明 対応バージョン
(constructor) コンストラクタ C++11
operator== 等値判定を行う C++11
operator!= 非等値判定を行う C++11
operator<=> 三方判定を行う C++20
operator< 左辺が右辺より小さいかの判定を行う C++11
operator<= 左辺が右辺以下かの判定を行う C++11
operator> 左辺が右辺より大きいかの判定を行う C++11
operator>= 左辺が右辺以上かの判定を行う C++11
hash_code ハッシュ値を取得する C++11
name 型名を取得する C++11

ハッシュサポート

名前 説明 対応バージョン
template <class T> struct hash; hashクラスの先行宣言 C++11
template <> struct hash<type_index>; hashクラスのtype_indexに対する特殊化 C++11

#include <iostream>
#include <map>
#include <typeindex>

int main()
{
  std::map<std::type_index, int> m = {
    { typeid(int),    3 },
    { typeid(double), 1 },
    { typeid(char),   4 }
  };

  std::cout << m.at(typeid(int)) << std::endl;
  std::cout << m.at(typeid(double)) << std::endl;
  std::cout << m.at(typeid(char)) << std::endl;
}

出力

3
1
4

言語

  • C++11

処理系

参照