A
Agoston Bejo
Hello,
I've got a template related problem. How do I express through template
metaprogramming or in a similar way that a class is convertible to a
template class for some T1?
I.e., the condition: "There exists some T1 such that B is convertible to
A<T1>".
An example program: (Platform: VC++7.1)
---------------------------------------------------
#include <iostream>
using namespace std;
template<typename T>
struct A {};
struct B : public A<int> {};
template<typename T>
struct isA
{
static const bool value = false;
};
template<typename T>
struct isA< A<T> >
{
static const bool value = true;
};
// This would give the desired result, but I don't know how it should
// legally be expressed it in C++ (if anyhow):
//template<typename T>
//struct isA< {{T where T is convertible to A<T1> for some T1}} >
//{
// static const bool value = true;
//};
int _tmain(int argc, _TCHAR* argv[])
{
cout << isA< A<int> >::value << endl; // 1
cout << isA< A<double> >::value << endl;// 1
cout << isA< B >::value << endl; // 0 - not what I want
cout << isA<int>::value << endl; // 0
return 0;
}
---------------------------------------------------
I've got a template related problem. How do I express through template
metaprogramming or in a similar way that a class is convertible to a
template class for some T1?
I.e., the condition: "There exists some T1 such that B is convertible to
A<T1>".
An example program: (Platform: VC++7.1)
---------------------------------------------------
#include <iostream>
using namespace std;
template<typename T>
struct A {};
struct B : public A<int> {};
template<typename T>
struct isA
{
static const bool value = false;
};
template<typename T>
struct isA< A<T> >
{
static const bool value = true;
};
// This would give the desired result, but I don't know how it should
// legally be expressed it in C++ (if anyhow):
//template<typename T>
//struct isA< {{T where T is convertible to A<T1> for some T1}} >
//{
// static const bool value = true;
//};
int _tmain(int argc, _TCHAR* argv[])
{
cout << isA< A<int> >::value << endl; // 1
cout << isA< A<double> >::value << endl;// 1
cout << isA< B >::value << endl; // 0 - not what I want
cout << isA<int>::value << endl; // 0
return 0;
}
---------------------------------------------------