Function template proxy_invoke
Header:
proxy.h
Module:proxy
Namespace:pro::inline v4
// (1)
template <class D, class O, facade F, class... Args>
return-type-of<O> proxy_invoke(proxy_indirect_accessor<F>& p, Args&&... args);
template <class D, class O, facade F, class... Args>
return-type-of<O> proxy_invoke(const proxy_indirect_accessor<F>& p, Args&&... args);
template <class D, class O, facade F, class... Args>
return-type-of<O> proxy_invoke(proxy_indirect_accessor<F>&& p, Args&&... args);
template <class D, class O, facade F, class... Args>
return-type-of<O> proxy_invoke(const proxy_indirect_accessor<F>&& p, Args&&... args);
// (2)
template <class D, class O, facade F, class... Args>
return-type-of<O> proxy_invoke(proxy<F>& p, Args&&... args);
template <class D, class O, facade F, class... Args>
return-type-of<O> proxy_invoke(const proxy<F>& p, Args&&... args);
template <class D, class O, facade F, class... Args>
return-type-of<O> proxy_invoke(proxy<F>&& p, Args&&... args);
template <class D, class O, facade F, class... Args>
return-type-of<O> proxy_invoke(const proxy<F>&& p, Args&&... args);
Invokes a proxy
with a specified dispatch type, an overload type, and arguments. Let Args2...
be the argument types of O
, R
be the return type of O
. return-type-of<O>
is R
.
(1)
Letptr
be the contained value of theproxy
object associated top
with the same cv ref-qualifiers. Equivalent toINVOKE<R>
(D(), *ptr, static_cast<Args2>(args)...)
.(2)
Letptr
be the contained value ofp
with the same cv ref-qualifiers. Equivalent toINVOKE<R>
(D(), ptr, static_cast<Args2>(args)...)
. The behavior is undefined ifp
does not contain a value.
There shall be a convention type Conv
defined in typename F::convention_types
where
Conv::is_direct
isfalse
(for(1)
) ortrue
(for(2)
), andtypename Conv::dispatch_type
isD
, and- there shall be an overload type
O1
defined intypename Conv::overload_types
wheresubstituted-overload
<O1, F>
isO
.
Notes
It is generally not recommended to call proxy_invoke
directly. Using an accessor
is usually a better option with easier and more descriptive syntax. If the facade type F
is defined with the recommended facilities, it has full accessibility support. Specifically, when
D
is defined via macroPRO_DEF_MEM_DISPATCH
, macroPRO_DEF_FREE_DISPATCH
, or is a specialization of eitheroperator_dispatch
orconversion_dispatch
, and- the convention type
Conv
is defined viafacade_builder
.
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 << pro::proxy_invoke<FreeToString, std::string() const>(*p)
<< "\n"; // Invokes with proxy_invoke, also prints: "123"
}