P
Patrick Kowalzick
Hello all,
I want to test run-time if a template function for a special type exists.
See example below. The checkfoo function is where I need some hints.
Regards,
Patrick
#include <iostream>
template <typename> struct fooclass;
template <> struct fooclass<int>
{
static void huhu()
{
std::cout << "int" << std::endl;
}
};
template <> struct fooclass<long>
{
static void huhu()
{
std::cout << "long" << std::endl;
}
};
template <typename T> void foo()
{
fooclass<T>::huhu();
}
template <typename T> bool checkfoo()
{
if ( foo<T>() ) return true; // check for existance here
else return false;
}
int main()
{
foo<int>();
foo<long>();
checkfoo<int>(); // should return true
checkfoo<double>(); // should return false
return 0;
}
I want to test run-time if a template function for a special type exists.
See example below. The checkfoo function is where I need some hints.
Regards,
Patrick
#include <iostream>
template <typename> struct fooclass;
template <> struct fooclass<int>
{
static void huhu()
{
std::cout << "int" << std::endl;
}
};
template <> struct fooclass<long>
{
static void huhu()
{
std::cout << "long" << std::endl;
}
};
template <typename T> void foo()
{
fooclass<T>::huhu();
}
template <typename T> bool checkfoo()
{
if ( foo<T>() ) return true; // check for existance here
else return false;
}
int main()
{
foo<int>();
foo<long>();
checkfoo<int>(); // should return true
checkfoo<double>(); // should return false
return 0;
}