c++ - Why does std::is_function evaluate to false when using on a dereferenced function pointer? -
i trying use std::is_function
determine if variable function pointer.
when running following code
#include <iostream> #include <typeinfo> using namespace std; int main() { typedef int(*functionpointer)(); functionpointer pmain = main; cout << typeid(functionpointer).name() << " "<< is_function<functionpointer>::value << endl; cout << typeid(decltype(pmain)).name() << " " << is_function<decltype(pmain)>::value << endl; cout << typeid(decltype(main)).name() << " " << is_function<decltype(main)>::value << endl; cout << typeid(decltype(*pmain)).name() << " " << is_function<decltype(*pmain)>::value << endl; return 0; }
the output is
pfive 0 pfive 0 5 1 5 0
can insight explain why last expression of std::is_function
evaluates false?
(code tested under g++4.7, g++4.8 , clang++3.2)
that because decltype(*pmain)
yield reference function type, std::function
false
intended. try:
is_function<remove_reference<decltype(*pmain)>::type>::value
btw: iso c++ forbids take address of ::main()
Comments
Post a Comment