Skip to content

Commit

Permalink
Implement PRO_DEF_FREE_AS_MEM_DISPATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxwa committed Oct 31, 2024
1 parent d742a33 commit 8921a64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class __T, class... __Args> \
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(); \
Expand Down
10 changes: 10 additions & 0 deletions tests/proxy_dispatch_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ struct PtrToMemTester {
private:
int value_;
};

PRO_DEF_FREE_AS_MEM_DISPATCH(FreeMemToString, std::to_string, ToString);

} // namespace

TEST(ProxyDispatchTests, TestOpPlus) {
Expand Down Expand Up @@ -613,3 +616,10 @@ TEST(ProxyDispatchTests, TestImplciitConversion) {
int converted = *p;
ASSERT_EQ(converted, 12);
}

TEST(ProxyDispatchTests, TestFreeAsMemDispatch) {
struct TestFacade : pro::facade_builder::add_convention<FreeMemToString, std::string() const>::build {};
int v = 123;
pro::proxy<TestFacade> p = &v;
ASSERT_EQ(p->ToString(), "123");
}

0 comments on commit 8921a64

Please sign in to comment.