Skip to content

Latest commit

 

History

History
82 lines (63 loc) · 2.83 KB

type_index.md

File metadata and controls

82 lines (63 loc) · 2.83 KB

type_index

  • typeindex[meta header]
  • std[meta namespace]
  • class[meta id-type]
  • cpp11[meta cpp]
namespace std {
  class type_index;
}

概要

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

メンバ関数

名前 説明 対応バージョン
(constructor) コンストラクタ C++11
operator== 等値判定を行う C++11
operator!= 非等値判定を行う C++11
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;
}
  • std::type_index[color ff0000]
  • m.at[link /reference/map/map/at.md]

出力

3
1
4

言語

  • C++11

処理系

参照