refl-cpp
refl::descriptor::function_descriptor< T, N > Class Template Reference

Represents a reflected function. More...

#include <refl.hpp>

Public Types

template<typename... Args>
using return_type = decltype(member::invoke(std::declval< Args >()...))
 The return type of an invocation of this member with Args... More...
 

Public Member Functions

template<typename... Args>
constexpr auto operator() (Args &&... args) const -> decltype(invoke(std::declval< Args >()...))
 A synonym for invoke(args...). More...
 

Static Public Member Functions

template<typename... Args>
static constexpr auto invoke (Args &&... args) -> decltype(member::invoke(std::declval< Args >()...))
 Invokes the function with the given arguments. More...
 
template<typename Pointer >
static constexpr bool can_resolve ()
 Whether the pointer can be resolved as with the specified type. More...
 
template<typename Pointer >
static constexpr auto resolve ()
 Resolves the function pointer as being of type Pointer. More...
 

Static Public Attributes

static constexpr auto pointer { detail::get_function_pointer<member>(0) }
 Returns a pointer to a non-overloaded function. More...
 
static constexpr bool is_resolved { !std::is_same_v<decltype(pointer), const decltype(nullptr)> }
 Whether the pointer member was correctly resolved to a concrete implementation. More...
 

Detailed Description

template<typename T, size_t N>
class refl::descriptor::function_descriptor< T, N >

Represents a reflected function.

Member Typedef Documentation

◆ return_type

template<typename T , size_t N>
template<typename... Args>
using refl::descriptor::function_descriptor< T, N >::return_type = decltype(member::invoke(std::declval<Args>()...))

The return type of an invocation of this member with Args...

(as if by invoke(...)).

Member Function Documentation

◆ can_resolve()

template<typename T , size_t N>
template<typename Pointer >
static constexpr bool refl::descriptor::function_descriptor< T, N >::can_resolve ( )
inlinestaticconstexpr

Whether the pointer can be resolved as with the specified type.

struct Foo {
void bar();
void bar(int);
};
REFL_AUTO(type(Foo), func(bar))
can_resolve<void(Foo::*)()>(get_t<0, member_list<Foo>>()) -> true
can_resolve<void(Foo::*)(int)>(get_t<0, member_list<Foo>>()) -> true
can_resolve<void(Foo::*)(std::string)>(get_t<0, member_list<Foo>>()) -> false

◆ invoke()

template<typename T , size_t N>
template<typename... Args>
static constexpr auto refl::descriptor::function_descriptor< T, N >::invoke ( Args &&...  args) -> decltype(member::invoke(std::declval<Args>()...))
inlinestaticconstexpr

Invokes the function with the given arguments.

If the function is an instance function, a reference to the instance is provided as first argument.

struct Foo {
int bar = 1;
static int baz = 5;
void foobar(int x) { return x * 2; }
static void foobaz(int x) { return x * 3; }
};
REFL_AUTO(type(Foo), field(bar), field(baz), func(foobar), func(foobaz))
invoke(get_t<0, member_list<Foo>(), Foo()) -> 1 (Foo().bar)
invoke(get_t<1, member_list<Foo>>()) -> 5 (Foo::baz)
invoke(get_t<2, member_list<Foo>(), Foo(), 10) -> 20 (Foo().foobar())
invoke(get_t<3, member_list<Foo>>()) -> 30 (Foo::foobaz())

◆ operator()()

template<typename T , size_t N>
template<typename... Args>
constexpr auto refl::descriptor::function_descriptor< T, N >::operator() ( Args &&...  args) const -> decltype(invoke(std::declval<Args>()...))
inlineconstexpr

A synonym for invoke(args...).

struct Foo {
int bar = 1;
static int baz = 5;
void foobar(int x) { return x * 2; }
static void foobaz(int x) { return x * 3; }
};
REFL_AUTO(type(Foo), field(bar), field(baz), func(foobar), func(foobaz))
invoke(get_t<0, member_list<Foo>(), Foo()) -> 1 (Foo().bar)
invoke(get_t<1, member_list<Foo>>()) -> 5 (Foo::baz)
invoke(get_t<2, member_list<Foo>(), Foo(), 10) -> 20 (Foo().foobar())
invoke(get_t<3, member_list<Foo>>()) -> 30 (Foo::foobaz())

◆ resolve()

template<typename T , size_t N>
template<typename Pointer >
static constexpr auto refl::descriptor::function_descriptor< T, N >::resolve ( )
inlinestaticconstexpr

Resolves the function pointer as being of type Pointer.

Required when taking a pointer to an overloaded function.

struct Foo {
void bar();
void bar(int);
};
REFL_AUTO(type(Foo), func(bar))
resolve<void(Foo::*)()>(get_t<0, member_list<Foo>>()) -> <&Foo::bar()>
resolve<void(Foo::*)(int)>(get_t<0, member_list<Foo>>()) -> <&Foo::bar(int)>
resolve<void(Foo::*)(std::string)>(get_t<0, member_list<Foo>>()) -> nullptr

Member Data Documentation

◆ is_resolved

template<typename T , size_t N>
constexpr bool refl::descriptor::function_descriptor< T, N >::is_resolved { !std::is_same_v<decltype(pointer), const decltype(nullptr)> }
staticconstexpr

Whether the pointer member was correctly resolved to a concrete implementation.

If this field is false, resolve() would need to be called instead.

struct Foo {
void bar();
void bar(int);
void baz();
};
REFL_AUTO(type(Foo), func(bar), func(baz))
is_resolved(get_t<0, member_list<Foo>>()) -> false
is_resolved(get_t<1, member_list<Foo>>()) -> true

◆ pointer

template<typename T , size_t N>
constexpr auto refl::descriptor::function_descriptor< T, N >::pointer { detail::get_function_pointer<member>(0) }
staticconstexpr

Returns a pointer to a non-overloaded function.

When the member is a function, the return value might be nullptr if the type of the function pointer cannot be resolved.

See also
is_resolved
can_resolve
resolve
struct Foo {
int bar;
static int baz;
};
REFL_AUTO(type(Foo), field(bar), field(baz))
get_pointer(get_t<0, member_list<Foo>>()) -> (int Foo::*) &Foo::bar
get_pointer(get_t<1, member_list<Foo>>()) -> (int*) &Foo::baz

The documentation for this class was generated from the following file:
refl::descriptor::function_descriptor::is_resolved
static constexpr bool is_resolved
Whether the pointer member was correctly resolved to a concrete implementation.
Definition: refl.hpp:2521
refl::descriptor::get_pointer
constexpr auto get_pointer(MemberDescriptor d) noexcept
Returns a pointer to the reflected field/function.
Definition: refl.hpp:2820
refl::trait::get_t
typename get< N, TypeList >::type get_t
The N-th type in the provided type_list.
Definition: refl.hpp:800
refl::descriptor::function_descriptor::invoke
static constexpr auto invoke(Args &&... args) -> decltype(member::invoke(std::declval< Args >()...))
Invokes the function with the given arguments.
Definition: refl.hpp:2488