std::is_function
Min standard notice:
Header: <type_traits>
std::is_function is a UnaryTypeTrait.
# Declarations
template< class T >
struct is_function;
(since C++11)
# Notes
std::is_function can be implemented in much simpler ways. Implementations similar to the following one are used by new versions of libc++, libstdc++ and MS STL:
The implementation shown below is for pedagogical purposes, since it exhibits the myriad kinds of function types.
# Example
#include <functional>
#include <type_traits>
int f();
static_assert(std::is_function_v<decltype(f)>);
static_assert(std::is_function_v<int(int)>);
static_assert(!std::is_function_v<int>);
static_assert(!std::is_function_v<decltype([]{})>);
static_assert(!std::is_function_v<std::function<void()>>);
struct O { void operator()() {} };
static_assert(std::is_function_v<O()>);
struct A
{
static int foo();
int fun() const&;
};
static_assert(!std::is_function_v<A>);
static_assert(std::is_function_v<decltype(A::foo)>);
static_assert(!std::is_function_v<decltype(&A::fun)>);
template<typename>
struct PM_traits {};
template<class T, class U>
struct PM_traits<U T::*> { using member_type = U; };
int main()
{
using T = PM_traits<decltype(&A::fun)>::member_type; // T is int() const&
static_assert(std::is_function_v<T>);
}