Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check type of element in stl container - c++

how can i get the type of the elements that are held by a STL container?

like image 578
Patrick Oscity Avatar asked Nov 10 '09 15:11

Patrick Oscity


2 Answers

container::value_type
like image 54
KeatsPeeks Avatar answered Nov 12 '22 13:11

KeatsPeeks


For containers in general it will be X::value_type. For associative containers it will be X::mapped_type (X::value_type corresponds to pair<const Key,T>). It is according to Chapter 23 of C++ Standard.

To check that types are equal you could use boost::is_same. And since C++11 — std::is_same.

like image 19
Kirill V. Lyadvinsky Avatar answered Nov 12 '22 15:11

Kirill V. Lyadvinsky