Skip to content

Class substitution_dispatch

Header: proxy.h
Module: proxy
Namespace: pro::inline v4
Since: 4.0.1

class substitution_dispatch;

Class substitution_dispatch models a dispatch type for proxy substitution. It meets the ProAccessible requirements of applicable types.

Member Functions

Name Description
(constructor) [nothrow] constructs an substitution_dispatch object
operator() invokes the dispatch

Member Types

Name Description
accessor provides accessibility to proxy

Example

#include <iostream>

#include <proxy/proxy.h>

struct Runnable : pro::facade_builder                                    //
                  ::add_convention<pro::operator_dispatch<"()">, void()> //
                  ::build {};

struct CopyableRunnable : pro::facade_builder                               //
                          ::support_copy<pro::constraint_level::nontrivial> //
                          ::add_facade<Runnable>                            //
                          ::add_direct_convention<pro::substitution_dispatch,
                                                  pro::proxy<Runnable>() const&,
                                                  pro::proxy<Runnable>() &&> //
                          ::build {};

int main() {
  pro::proxy<CopyableRunnable> p1 = pro::make_proxy<CopyableRunnable>(
      [] { std::cout << "Lambda expression invoked\n"; });

  // Implicit conversion via const reference of pro::proxy<CopyableRunnable>
  pro::proxy<Runnable> p2 = p1;
  std::cout << std::boolalpha << p2.has_value() << "\n"; // Prints "true"

  // Implicit conversion via rvalue reference of pro::proxy<CopyableRunnable>
  pro::proxy<Runnable> p3 = std::move(p1);
  std::cout << p1.has_value() << "\n"; // Prints "false"
  (*p3)();                             // Prints "Lambda expression invoked"

  // Different from implicit_conversion_dispatch, substitution from a null proxy
  // is well-formed
  pro::proxy<Runnable> p4 = p1;
  std::cout << p4.has_value() << "\n"; // Prints "false"
}

See Also