I am learning writing my own traits using C++11 borrowing only std::true_type and std::false_type.
I've created the following trait:
#include <iostream>
template <typename F>
struct is_farg1: std::false_type {};
template <typename R, typename A>
struct is_farg1<R (*)(A)> : std::true_type {};
Now consider a program including the above trait, and the following code:
void f(int) {}
int main() {
std::cout << "is_farg1<decltype(f)> : " << is_farg1<decltype(f)>::value << std::endl;
std::cout << "is_farg1<void(*)(int)> : " << is_farg1<void(*)(int)>::value << std::endl;
return 0;
}
It produces the following output:
is_farg1<decltype(f)> : 0
is_farg1<void(*)(int)> : 1
My questions:
- Why
is_farg1<void(*)(int)>::valueistruewhileis_farg1<decltype(f)>::valuereturnedfalse? - If my trait is incorrectly written then how can I check if the given function has one and only one argument so I could use also
decltype(f)?