std::meta::is_function_type
From cppreference.com
| Defined in header <meta>
|
||
consteval bool is_function_type( std::meta::info r );
|
(since C++26) | |
Returns true if r represents a function type. Otherwise returns false.
Types like std::function, lambdas, classes with overloaded operator() and pointers to functions are not function types.
Parameters
| r | - | a reflection value |
Return value
true if r represents a function type; otherwise false.
Exceptions
Throws std::meta::exception if r does not represent a type or type alias.
Example
Run this code
#include <functional>
#include <meta>
int f();
struct O
{
void operator()() {}
};
static_assert
(""
&& is_function_type(^^decltype(f))
&& ! is_function_type(^^int)
&& is_function_type(^^int(int))
&& ! is_function_type(^^decltype([]{}))
&& is_function_type(^^O())
&& ! is_function_type(^^std::function<void()>)
);
struct A
{
static int foo();
int fun() const&;
int operator()();
};
static_assert
(""
&& ! is_function_type(^^A)
&& is_function_type(^^decltype(A::foo))
&& ! is_function_type(^^decltype(&A::fun))
&& ! is_function_type(^^decltype(&A::operator()))
);
template<typename>
struct is_member_pointer {};
template<class T, class U>
struct is_member_pointer<U T::*> { using type = U; };
using T = is_member_pointer<decltype(&A::fun)>::type; // T is int() const&
static_assert(is_function_type(^^T));
int main() {}
See also
(C++26)(C++26)(C++26)(C++26) |
checks if the reflected type can be invoked (as if by std::invoke) with the given argument types (function template) |
(C++26) |
checks if reflected type is an object type (function) |
(C++26) |
checks if reflected type is a non-union class type (function) |
(C++11) |
checks if a type is a function type (class template) |