Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 1.42 KB

File metadata and controls

59 lines (44 loc) · 1.42 KB

Function template make_proxy_view

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

template <facade F, class T>
proxy_view<F> make_proxy_view(T& value) noexcept;

Equivalent to return make_proxy_observed<observer_facade<F>>(value).

Return Value

The constructed proxy_view object.

Example

#include <iostream>
#include <map>
#include <string>

#include <proxy/proxy.h>

PRO_DEF_MEM_DISPATCH(MemAt, at);

struct ResourceDictionary
    : pro::facade_builder //
      ::add_convention<MemAt, std::string&(int index),
                       const std::string&(int index) const> //
      ::build {};

int main() {
  std::map<int, std::string> dict;
  dict[1] = "init";
  pro::proxy_view<ResourceDictionary> pv =
      pro::make_proxy_view<ResourceDictionary>(dict);
  static_assert(std::is_same_v<decltype(pv->at(1)), std::string&>,
                "Non-const overload");
  static_assert(
      std::is_same_v<decltype(std::as_const(pv)->at(1)), const std::string&>,
      "Const overload");

  // Invokes the const overload and prints "init"
  std::cout << std::as_const(pv)->at(1) << "\n";
  pv->at(1) = "modified"; // Invokes the non-const overload

  // Invokes the const overload and prints "modified"
  std::cout << std::as_const(pv)->at(1) << "\n";
}

See Also