Consider the following code:
#include <iostream>
#include <typeinfo>
#include <map>
int main(int argc, const char* argv[]) {
typedef std::map<int,float> testmap;
typedef std::map<int,float> testmap2;
typedef std::map<typename testmap::value_type::first_type, typename testmap::value_type::second_type> rebuiltMap;
std::cout << "map samenes: " << std::is_same<testmap, rebuiltMap>::value << "\n";
std::cout << "map samenes: " << std::is_same<testmap, testmap2>::value << "\n";
std::cout << "original map type name " << typeid(testmap).name() << "\n";
std::cout << "same map type name " << typeid(testmap2).name() << "\n";
std::cout << "rebuilt map type name " << typeid(rebuiltMap).name() << "\n";
std::cout << "original map valuetype " << typeid(testmap::value_type).name() << "\n";
std::cout << "rebuilt map valuetype " << typeid(rebuiltMap::value_type).name() << "\n";
}
This produces the following output:
map samenes: 0 map samenes: 1 original map type name St3mapIifSt4lessIiESaISt4pairIKifEEE same map type name St3mapIifSt4lessIiESaISt4pairIKifEEE rebuilt map type name St3mapIKifSt4lessIS0_ESaISt4pairIS0_fEEE original map valuetype St4pairIKifE rebuilt map valuetype St4pairIKifE
Why is the "rebuilt" map type different from the simple map type, although both have the same value_type? Background: i want to test if a container containing pairs is a map or not with a construct like
std::is_same<std::map<typename Container::value_type::first_type,
typename Container::value_type::second_type>,
Container>::value