template<class Access>
struct ugmisc::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:
#define UGMISC_DECL_MEMBER_ACCESS(TNAME, NAME)
Definition member.hpp:148
static constexpr default_function< F > fallback(F &&f)
Definition member.hpp:925
val is the value of the first of these expressions which is valid:
- x.foo(1, 2)
- std::invoke(x.foo, 1, 2)
- y.foo(1, 2)
- std::invoke(y.foo, 1, 2)
- get_default(1, 2)
- get_default()
The inclusion of the std::invoke variant of the call allows a tried object to have a poiner-to-member member called foo, and the first argument supplied is then the object whose member will be the callable that takes the rest of the arguments.
- Note
- In C++17, std::invoke is not constexpr. std::invoke is declared constexpr starting with C++20.
It may be more convenient to use member_caller as an object.
auto val = caller.
fallback( get_default )(x, y)(1, 2);
Definition member.hpp:745
...or even (if it is safe to keep the references to x and y alive):