proxy_invoke
template <bool IsDirect, class D, class O, facade F, class... Args>
/* see below */ proxy_invoke(proxy<F>& p, Args&&... args);
template <bool IsDirect, class D, class O, facade F, class... Args>
/* see below */ proxy_invoke(const proxy<F>& p, Args&&... args);
template <bool IsDirect, class D, class O, facade F, class... Args>
/* see below */ proxy_invoke(proxy<F>&& p, Args&&... args);
template <bool IsDirect, class D, class O, facade F, class... Args>
/* see below */ proxy_invoke(const proxy<F>&& p, Args&&... args);
Invokes a proxy
with a specified dispatch type, an overload type, and arguments. There shall be a convention type Conv
defined in typename F::convention_types
where
Conv::is_direct == IsDirect
is true
, andtypename Conv::dispatch_type
is D
, andO1
defined in typename Conv::overload_types
where substituted-overload
<O1, F>
is O
.Let ptr
be the contained value of p
with the same cv ref-qualifiers, Args2...
be the argument types of O
, R
be the return type of O
,
IsDirect
is true
, let v
be std::forward<decltype(ptr)>(ptr)
, or otherwise,IsDirect
is false
, let v
be *std::forward<decltype(ptr)>(ptr)
,equivalent to:
INVOKE<R>
(D{}, std::forward<decltype(v)>(v), static_cast<Args2>(args)...)
if the expression is well-formed, or otherwise,INVOKE<R>
(D{}, nullptr, static_cast<Args2>(args)...)
.The behavior is undefined if p
does not contain a value.
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 macro PRO_DEF_MEM_DISPATCH
, macro PRO_DEF_FREE_DISPATCH
, or is a specialization of either operator_dispatch
or conversion_dispatch
, andConv
is defined via facade_builder
.#include <iostream>
#include <string>
#include "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<false, FreeToString, std::string() const>(p) << "\n"; // Invokes with proxy_invoke, also prints: "123"
}