Movatterモバイル変換


[0]ホーム

URL:


Skip to content

MacroPRO_DEF_MEM_DISPATCH

Header:proxy_macros.h andproxy.h

#define PRO_DEF_MEM_DISPATCH// see below

MacroPRO_DEF_MEM_DISPATCH defines dispatch types for member function expressions with accessibility. It supports two syntaxes:

// (1)PRO_DEF_MEM_DISPATCH(dispatch_name,func_name);// (2)PRO_DEF_MEM_DISPATCH(dispatch_name,func_name,accessibility_func_name);

(1) Equivalent toPRO_DEF_MEM_DISPATCH(dispatch_name, func_name, func_name).

(2) Defines a class nameddispatch_name of member function call expressions offunc_name with accessibility via member function overloads namedaccessibility_func_name. Effectively equivalent to:

structdispatch_name{template<classT,class...Args>decltype(auto)operator()(T&&self,Args&&...args)constnoexcept(noexcept(std::forward<T>(self).func_name(std::forward<Args>(args)...)))requires(requires{std::forward<T>(self).func_name(std::forward<Args>(args)...);}){returnstd::forward<T>(self).func_name(std::forward<Args>(args)...);}template<classP,classD,class...Os>structaccessor{accessor()=delete;};template<classP,classD,class...Os>requires(sizeof...(Os)>1u&&(std::is_constructible_v<accessor<P,D,Os>>&&...))structaccessor<P,D,Os...>:accessor<P,D,Os>...{usingaccessor<P,D,Os>::accessibility_func_name...;};template<classP,classD,classR,class...Args>structaccessor<P,D,R(Args...)cvrefnoex>{Raccessibility_func_name(Args...args)cvrefnoex{returnpro::proxy_invoke<D,R(Args...)cvrefnoex>(static_cast<Pcv<ref?ref:&>>(*this),std::forward<Args>(args)...);}};}

When headers from different major versions of the Proxy library can appear in the same translation unit (for example, Proxy 3 and Proxy 4), use the major-qualified formPRO<major>_DEF_MEM_DISPATCH (e.g.,PRO4_DEF_MEM_DISPATCH).

Example

#include<iostream>#include<string>#include<vector>#include<proxy/proxy.h>PRO_DEF_MEM_DISPATCH(MemAt,at);structDictionary:pro::facade_builder//::add_convention<MemAt,std::string(intindex)const>//::build{};intmain(){std::vector<constchar*>v{"hello","world"};pro::proxy<Dictionary>p=&v;std::cout<<p->at(1)<<"\n";// Prints "world"}

See Also

July 14, 2025

[8]ページ先頭

©2009-2026 Movatter.jp