I am learning write my own traits using C++11 borrowing only std::true_type
and std::false_type
Why is_farg1<void(*)(int)>::value
is true
while is_farg1<decltype(f)>::value
returned false
?
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)
?
#include <iostream>
template <typename F>
template <typename F>
struct is_farg1: std::false_type {};
template <typename R, typename A>
struct is_farg1<R (*)(A)> : std::true_type {};
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;
}
Output:
is_farg1<decltype(f)> : 0
is_farg1<void(*)(int)> : 1
Aucun commentaire:
Enregistrer un commentaire