#include <ugmisc/member.hpp>
Public Types | |
| template<class... Args> | |
| using | matched_type = typename caller<void, types_list, Args...>::type |
Public Member Functions | |
| template<class... Args> | |
| constexpr decltype(auto) | operator() (Args &&...args) const |
Static Public Member Functions | |
| template<class... Args> | |
| static constexpr bool | is_matched (Args &&...) |
| template<class... Args> | |
| static constexpr decltype(auto) | call (Args &&...args) |
| template<class F> | |
| static constexpr member_::fallback_caller< static_member_caller, F > | fallback (F &&functor) |
| template<class... Args> | |
| static matched_type< Args... > | declval_matched (Args &&...) noexcept |
| template<class... Args> | |
| static matched_type< Args... > | declval_matched () noexcept |
| template<class... Args> | |
| static safe_matched_type< Args... > | safe_declval_matched (Args &&...) noexcept |
| template<class... Args> | |
| static safe_matched_type< Args... > | safe_declval_matched () noexcept |
Static Public Attributes | |
| template<class... Args> | |
| static constexpr bool | is_matched_v |
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.
| 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:
Continuing the above example:
The first of the following expressions which is valid is what the above expression is equivalent to (but with proper forwarding):
f would typically be a lambda.
The use of std::invoke allows (for example) X::foo to be a pointer-to-member and the first argument in args to be the object containing the member. However, trying the direct call first allows overload resolution among different X::foo functions.
If all you want to know is whether the call with those arguments would be valid:
You can also find the type whose foo method would be called:
Definition at line 573 of file member.hpp.
| using ugmisc::static_member_caller< Access, T >::matched_type = typename caller<void, types_list, Args...>::type |
The type, which is one of the T... template parameter pack, that would be called if call were called with these argument types.
Definition at line 622 of file member.hpp.
|
inlinestaticconstexpr |
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.
Definition at line 644 of file member.hpp.
|
staticnoexcept |
Like declval_matched(Args&&...) but is more convenient when you have argument types handy rather than argument expressions.
|
staticnoexcept |
Can be used like std::declval, passing it the type whose named method the arguments would be forwarded to.
|
inlinestaticconstexpr |
Definition at line 671 of file member.hpp.
|
inlinestaticconstexpr |
true if the call with the provided arguments would be valid.
Definition at line 613 of file member.hpp.
|
inlineconstexpr |
An instance of static_member_caller is callable using its operator (). It simply forwards its arguments, using std::forward, to its static call method.
Definition at line 659 of file member.hpp.
|
staticnoexcept |
|
staticnoexcept |
Like declval_matched(Args&&...) but it will create a void expression instead of a compile error. This is likely to cause a compile error in whatever you were trying to do anyway.
|
staticconstexpr |
true if one of the listed types has a static method named by the Access template parameter, which would accept the arguments of the same type as Args....
Definition at line 606 of file member.hpp.