Function template invoke (proxy_indirect_accessor<F>)
Since: 4.1.0
template <class D, class O, class... Args>
return-type-of<O> invoke(proxy_indirect_accessor<F>& p, Args&&... args);
template <class D, class O, class... Args>
return-type-of<O> invoke(const proxy_indirect_accessor<F>& p, Args&&... args);
template <class D, class O, class... Args>
return-type-of<O> invoke(proxy_indirect_accessor<F>&& p, Args&&... args);
template <class D, class O, class... Args>
return-type-of<O> invoke(const proxy_indirect_accessor<F>&& p, Args&&... args);
Invokes a proxy_indirect_accessor<F> with a specified dispatch type D, an overload type O, and arguments, through an indirect convention. Let Args2... be the argument types of O, R be the return type of O. return-type-of<O> is R.
Let ptr be the contained value of the proxy object associated to p with the same cv ref-qualifiers. Equivalent to INVOKE<R>(D(), *ptr, static_cast<Args2>(args)...).
There shall be a convention type Conv defined in typename F::convention_types where
Conv::is_directisfalse, andtypename Conv::dispatch_typeisD, and- there shall be an overload type
O1defined intypename Conv::overload_typeswheresubstituted-overload<O1, F>isO.
This function is not visible to ordinary unqualified or qualified lookup. It can only be found by argument-dependent lookup when proxy_indirect_accessor<F> is an associated class of the arguments.
A proxy_indirect_accessor<F> is obtained by dereferencing a proxy<F> (i.e., *p). To invoke a direct convention, use invoke on the proxy<F> itself.
Notes
invoke was introduced in 4.1.0 as a replacement for the deprecated proxy_invoke. proxy_invoke is a namespace-scope function, while invoke is a non-member function of proxy_indirect_accessor found only via argument-dependent lookup.
It is generally not recommended to call invoke directly. Using an accessor is usually a better option with easier and more descriptive syntax.
Example
#include <iostream>
#include <string>
#include <proxy/proxy.h>
PRO_DEF_FREE_DISPATCH(FreeToString, std::to_string, ToString);
struct Stringable : pro::facade_builder //
::add_convention<FreeToString, std::string() const> //
::build {};
int main() {
int a = 123;
pro::proxy<Stringable> p = &a;
std::cout << ToString(*p) << "\n"; // Invokes with accessor, prints: "123"
std::cout << invoke<FreeToString, std::string() const>(*p)
<< "\n"; // Invokes with the non-member invoke, also prints: "123"
}