From 531dfcc35823e9697147b8f7c8a6e954c2ad6c35 Mon Sep 17 00:00:00 2001 From: Mingxin Wang Date: Tue, 16 Jan 2024 22:35:24 +0800 Subject: [PATCH] Add support for combination of incomplete dispatch (#58) --- proxy.h | 14 ++++++++++++-- tests/proxy_invocation_tests.cpp | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/proxy.h b/proxy.h index a38ce9f..e6bb23d 100644 --- a/proxy.h +++ b/proxy.h @@ -614,12 +614,22 @@ struct flattening_traits> : flattening_traits_impl< typename flattening_traits::type, typename flattening_traits>::type> {}; +template +struct overloads_combination_traits { using type = std::tuple<>; }; +template +struct overloads_combination_traits + : overloads_combination_traits {}; +template + requires(requires { typename D::overload_types; }) +struct overloads_combination_traits + : flattening_traits::type>> {}; + template requires(sizeof...(Os) > 0u) struct dispatch_prototype { using overload_types = std::tuple; }; template requires(sizeof...(Ds) > 0u) struct combined_dispatch_prototype : Ds... { - using overload_types = typename flattening_traits< - std::tuple>::type; + using overload_types = typename overloads_combination_traits::type; using Ds::operator()...; }; template , proxiable_ptr_constraints C = diff --git a/tests/proxy_invocation_tests.cpp b/tests/proxy_invocation_tests.cpp index 218def4..c8a1324 100644 --- a/tests/proxy_invocation_tests.cpp +++ b/tests/proxy_invocation_tests.cpp @@ -169,3 +169,26 @@ TEST(ProxyInvocationTests, TestFunctionPointer) { auto ret = p(); ASSERT_EQ(ret, (GetTypeIndices())); } + +TEST(ProxyInvocationTests, TestCombinationWithIncompleteDispatch) { + constexpr auto not_implemented = [](auto&&...) { throw std::runtime_error{ "Not implemented!" }; }; + PRO_DEF_COMBINED_DISPATCH(WeakCall, poly::Call, decltype(not_implemented)); + PRO_DEF_FACADE(WeakCallable, WeakCall); + { + int side_effect = 0; + auto p = pro::make_proxy([&] { side_effect = 1; }); + p(); + ASSERT_EQ(side_effect, 1); + } + { + bool exception_thrown = false; + auto p = pro::make_proxy(123); + try { + p(); + } catch (const std::runtime_error& e) { + exception_thrown = true; + ASSERT_EQ(static_cast(e.what()), "Not implemented!"); + } + ASSERT_TRUE(exception_thrown); + } +}