access_proxy
template <class F, class A>
proxy<F>& access_proxy(A& a) noexcept;
template <class F, class A>
const proxy<F>& access_proxy(const A& a) noexcept;
template <class F, class A>
proxy<F>&& access_proxy(A&& a) noexcept;
template <class F, class A>
const proxy<F>&& access_proxy(const A&& a) noexcept;
Accesses a proxy
object from an accessor instantiated from the proxy
. F
shall model concept facade
. As per facade<F>
, typename F::convention_types
shall be a tuple-like type containing distinct types Cs
. There shall be a type C
in Cs
where A
is the same type as typename C::template accessor<F>
. The behavior is undefined if a
is not instantiated from a proxy
.
A reference to the proxy
that instantiates a
.
Similar to proxy_invoke
, this function can be used to implement the accessibility of proxy
. If the facade type F
is defined with the recommended facilities, it has full accessibility support. Specifically, when:
typename C::dispatch_type
is defined via macro PRO_DEF_MEM_DISPATCH
, macro PRO_DEF_FREE_DISPATCH
, or is a specialization of either operator_dispatch
or conversion_dispatch
, andfacade_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()>
::build {};
int main() {
pro::proxy<Stringable> p = pro::make_proxy<Stringable>(123);
// Invokes with accessibility API
std::cout << ToString(*p) << "\n"; // Prints: "123"
// How it works behind the scenes
using Convention = std::tuple_element_t<0u, Stringable::convention_types>;
using Accessor = Convention::accessor<Stringable>;
static_assert(std::is_base_of_v<Accessor, std::remove_reference_t<decltype(*p)>>);
Accessor& a = static_cast<Accessor&>(*p);
pro::proxy<Stringable>& p2 = pro::access_proxy<Stringable>(a);
std::cout << std::boolalpha << (&p == &p2) << "\n"; // Prints: "true" because access_proxy converts
// an accessor back to the original proxy
auto result = pro::proxy_invoke<Convention, std::string()>(p2);
std::cout << result << "\n"; // Prints: "123"
}