Spec-Zone.ru › C++

std::meta::is_function_type

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

#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

is_invocable_typeis_invocable_r_typeis_nothrow_invocable_typeis_nothrow_invocable_r_type
(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)
is_object_type
(C++26)
checks if reflected type is an object type
(function)
is_class_type
(C++26)
checks if reflected type is a non-union class type
(function)
is_function
(C++11)
checks if a type is a function type
(class template)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/meta/is_function_type

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API