My code is supposed is to determine if the given function takes the given type as a parameter. Answering your future "what for" questions I will shortly answer: to use it with boost::enable_if
template.
The code uses decltype operator of the C++11. My question is: Is it possible to achieve the same goal using c++03?
#include <iostream>
template <class F, class P>
struct has_arg_of_type
{
static bool const value = false;
};
template <class R, class A>
struct has_arg_of_type<R (A), A>
{
static bool const value = true;
};
template <class R, class T, class A>
struct has_arg_of_type<R (T::*)(A), A>
{
static bool const value = true;
};
int pisz(int);
class MyClass
{
public:
void pisz(int);
};
int main(int argc, char *argv[])
{
std::cout << "MyClass::pisz has the int as an argument? " << has_arg_of_type<decltype(&MyClass::pisz), int>::value << std::endl; // Line 32
std::cout << "pisz has the int as an argument? ? " << has_arg_of_type<decltype(pisz), int>::value << std::endl;
std::cout << "pisz has the float as an argument? ? " << has_arg_of_type<decltype(pisz), float>::value << std::endl;
return 0;
}
The error is:
In function 'int main(int, char**)':
Line 32: error: 'MyClass::pisz(int)' cannot appear in a constant-expression