ugmisc 0.2-76
Miscellaneous C++ header library
Loading...
Searching...
No Matches
member_caller< Access > Struct Template Reference

#include <ugmisc/member.hpp>

Public Member Functions

template<class... T>
constexpr auto operator() (T &&...objs) const

Static Public Member Functions

template<class F>
static constexpr default_function< F > fallback (F &&f)
template<class... T>
static constexpr wrapped_objects< void, T... > with (T &&...objs)

Detailed Description

template<class Access>
struct member_caller< Access >

Calls a named member function of objects, trying them in sequence until one will accept the arguments, optionally providing a fallback default value.

For example:

UGMISC_DECL_MEMBER_ACCESS(Access, foo); // Declares a foo accessor called Access.
auto val = member_caller<Access>::fallback( get_default )(x, y)(1, 2);
#define UGMISC_DECL_MEMBER_ACCESS(TNAME, NAME)
Definition member.hpp:165
static constexpr default_function< F > fallback(F &&f)
Definition member.hpp:942

val is the value of the first of these expressions which is valid:

  1. x.foo(1, 2)
  2. y.foo(1, 2)
  3. get_default(1, 2)
  4. get_default()

It may be more convenient to use member_caller as an object.

UGMISC_DECL_MEMBER_ACCESS(Access, foo); // Declares a foo accessor called Access.
auto caller = member_caller<Access>{};
auto val = caller.fallback( get_default )(x, y)(1, 2);
Definition member.hpp:762

...or even (if it is safe to keep the references to x and y alive):

UGMISC_DECL_MEMBER_ACCESS(Access, foo); // Declares a foo accessor called Access.
auto caller = member_caller<Access>::fallback( get_default )(x, y);
auto val = caller(1, 2);

Member Function Documentation

◆ fallback()

template<class Access>
template<class F>
constexpr default_function< F > member_caller< Access >::fallback ( F && f)
inlinestaticconstexpr
Parameters
fA function or other callable which provides a default value if none of the objects can be called.

◆ with()

template<class Access>
template<class... T>
constexpr wrapped_objects< void, T... > member_caller< Access >::with ( T &&... objs)
inlinestaticconstexpr
Parameters
objsObjects to try calling.

The documentation for this struct was generated from the following file: