diff --git a/proxy.h b/proxy.h index 0623c2d..099c8ad 100644 --- a/proxy.h +++ b/proxy.h @@ -1582,6 +1582,21 @@ struct conversion_dispatch { #define PRO_DEF_FREE_DISPATCH(__NAME, ...) \ ___PRO_EXPAND_MACRO(___PRO_DEF_FREE_DISPATCH, __NAME, __VA_ARGS__) +#define ___PRO_DEF_FREE_AS_MEM_DISPATCH_IMPL(__NAME, __FUNC, __FNAME) \ + struct __NAME { \ + template \ + decltype(auto) operator()(__T&& __self, __Args&&... __args) \ + ___PRO_DIRECT_FUNC_IMPL(__FUNC(::std::forward<__T>(__self), \ + ::std::forward<__Args>(__args)...)) \ + ___PRO_DEF_MEM_ACCESSOR_TEMPLATE(___PRO_DEF_MEM_ACCESSOR, __FNAME) \ + } +#define ___PRO_DEF_FREE_AS_MEM_DISPATCH_2(__NAME, __FUNC) \ + ___PRO_DEF_FREE_AS_MEM_DISPATCH_IMPL(__NAME, __FUNC, __FUNC) +#define ___PRO_DEF_FREE_AS_MEM_DISPATCH_3(__NAME, __FUNC, __FNAME) \ + ___PRO_DEF_FREE_AS_MEM_DISPATCH_IMPL(__NAME, __FUNC, __FNAME) +#define PRO_DEF_FREE_AS_MEM_DISPATCH(__NAME, ...) \ + ___PRO_EXPAND_MACRO(___PRO_DEF_FREE_AS_MEM_DISPATCH, __NAME, __VA_ARGS__) + #define PRO_DEF_WEAK_DISPATCH(__NAME, __D, __FUNC) \ struct __NAME : __D { \ using __D::operator(); \ diff --git a/tests/proxy_dispatch_tests.cpp b/tests/proxy_dispatch_tests.cpp index 95ccc68..901d135 100644 --- a/tests/proxy_dispatch_tests.cpp +++ b/tests/proxy_dispatch_tests.cpp @@ -32,6 +32,9 @@ struct PtrToMemTester { private: int value_; }; + +PRO_DEF_FREE_AS_MEM_DISPATCH(FreeMemToString, std::to_string, ToString); + } // namespace TEST(ProxyDispatchTests, TestOpPlus) { @@ -613,3 +616,10 @@ TEST(ProxyDispatchTests, TestImplciitConversion) { int converted = *p; ASSERT_EQ(converted, 12); } + +TEST(ProxyDispatchTests, TestFreeAsMemDispatch) { + struct TestFacade : pro::facade_builder::add_convention::build {}; + int v = 123; + pro::proxy p = &v; + ASSERT_EQ(p->ToString(), "123"); +}