LoginSignup
7
4

More than 5 years have passed since last update.

C++11のtypeinfoについて

Posted at

実行時型情報(Run Time Type Info: RTTI)をC++11で得るには、
#include <typeinfo>してtypeid(型名や変数名)する。
人間が可読な形式にするにはtypeid(型名や変数名).name()すればいい。
ところが、どうも実装によっては人間可読ではない、
もしくは、暗黙の了解な形式で出力されることがある。
例えば、intは、MSVCではintだが、OSXのclang++ではiと表示される。
(コンパイラの問題なのか標準ライブラリの問題なのかは調べていない)
原子的な型なら一文字でもわかるが(int, char, void, bool, float, double)、signedunsigned,longなどの修飾子が付いたものは一文字だと何のことやらわからないので、調べたものをここに貼り付けておく。


type letter
int i
float f
double d
char c
void v
bool b
short s
signed char a
unsigned int j
unsigned char h
unsigned short t
long int l
long double e
long long int x
unsigned long int m
unsigned long long int y
wchar_t w
size_t m

(size_tはloopのカウンタの型に使うと便利なやつ
for(size_t i=0; i<max; i++)みたいな
)

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4