template<class Access, class... T>
struct static_member_caller< Access, T >
Can find, among a list of types, a static method with a particular name, which accepts certain parameter types, and forward arguments to it.
Also provides the ability to revert to a default value if no suitable call can be made. This can be done in such a way that the default value does not have to be instantiated if it is not needed.
- Template Parameters
-
| Access | A type, which may be declared using UGMISC_DECL_MEMBER_ACCESS, which is responsible for knowing the name of the function to call. |
| T | A list of types which may or may not contain the named static method. The first one which is suitable will be selected. |
For example, if you want to forward args... to the first of X::foo(), Y::foo(), and Z::foo() which accepts those arguments, you can do this:
F::call(args...);
F().call(args...);
F()(args...);
#define UGMISC_DECL_MEMBER_ACCESS(TNAME, NAME)
Definition member.hpp:165
Definition member.hpp:593
Default values
Continuing the above example:
F::fallback( f )(args...);
F().fallback( f )(args...);
The first of the following expressions which is valid is what the above expression is equivalent to:
- X::foo(args...)
- Y::foo(args...)
- Z::foo(args...)
- f(args...)
- f()
f would typically be a lambda.
If all you want to know is whether the call with those arguments would be valid:
F::is_matched(args...);
F::is_matched_v<ArgTypes...>;
You can also find the type whose foo method would be called:
F::matched_type<ArgTypes...>;
F::safe_matched_type<ArgTypes...>;
template<class Access, class... T>
template<class... Args>
If is_matched_v<Args...> is true: the type whose named (by Access) method would be called by call<Args...>.
If is_matched_v<Args...> is false: void`. */ template<class...Args> using safe_matched_type = typename caller<void, types_list, Args...>::safe_type;
/** Forward the arguments, using std::forward, to a static method of one of the types T....
The name of the static method is determined by the Access template parameter.
The first type for which the call would be valid is used.