
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 1.15 KB | hits: 11 | expires: Never
Strange behaviour of the following template code
#include <typeinfo>
#include <stdio.h>
#include <string>
template <typename T>
struct StripTag
{typedef T Type;};
template<typename T, template<typename T> class Tag >
struct StripTag<Tag<T> >
{ typedef typename StripTag<T>::Type Type; };
template<typename T, typename X, template<typename T, typename X> class Tag >
struct StripTag<Tag<T,X> >
{ typedef typename StripTag<T>::Type Type; };
/*
//UNCOMMENT THIS AND RECOMPILE
template<typename T, typename X, typename Y, template<typename T, typename X, typename Y> class Tag >
struct StripTag<Tag<T,X,Y> >
{ typedef typename StripTag<T>::Type Type; };
*/
template <class C>
struct Test
{
typedef C Type;
};
template <typename A, typename B>
struct Blah{};
int main()
{
printf("typeid of StripTag=t%sn", typeid(StripTag<std::string>::Type).name());
printf("typeid of StripTag2=t%sn", typeid(StripTag<Blah<std::string, bool> >::Type).name());
printf("typeid of Test=tt%sn", typeid(Test<std::string>::Type).name());
printf("typeid of std::string=t%sn", typeid(std::string).name());
}
std::basic_string<char, std::char_traits<char>, std::allocator<char>>