A
avasilev
Hi all,
In the code below, when the signified code is commented out, code
works as expected - Type matches the (first) template argument.
However, if I uncomment it, Type becomes 'char' instead of
std::string. This is the same with both MSVC and GCC. So it works when
I have specialization of StripTag for a tag template with one and two
arguments, but when I specialize it in exactly the same way for three
arguments, I get this strange behavior.
Anyone has any ideas?
Code follows:
#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%s\n",
typeid(StripTag<std::string>::Type).name());
printf("typeid of StripTag2=\t%s\n", typeid(StripTag<Blah<std::string,
bool> >::Type).name());
printf("typeid of Test=\t\t%s\n",
typeid(Test<std::string>::Type).name());
printf("typeid of std::string=\t%s\n", typeid(std::string).name());
}
In the code below, when the signified code is commented out, code
works as expected - Type matches the (first) template argument.
However, if I uncomment it, Type becomes 'char' instead of
std::string. This is the same with both MSVC and GCC. So it works when
I have specialization of StripTag for a tag template with one and two
arguments, but when I specialize it in exactly the same way for three
arguments, I get this strange behavior.
Anyone has any ideas?
Code follows:
#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%s\n",
typeid(StripTag<std::string>::Type).name());
printf("typeid of StripTag2=\t%s\n", typeid(StripTag<Blah<std::string,
bool> >::Type).name());
printf("typeid of Test=\t\t%s\n",
typeid(Test<std::string>::Type).name());
printf("typeid of std::string=\t%s\n", typeid(std::string).name());
}