Skip to content

Commit

Permalink
Add support for combination of incomplete dispatch (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
mingxwa authored Jan 16, 2024
1 parent d3b69dd commit 531dfcc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
14 changes: 12 additions & 2 deletions proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,22 @@ struct flattening_traits<std::tuple<T, Ts...>> : flattening_traits_impl<
typename flattening_traits<T>::type,
typename flattening_traits<std::tuple<Ts...>>::type> {};

template <class... Ds>
struct overloads_combination_traits { using type = std::tuple<>; };
template <class D, class... Ds>
struct overloads_combination_traits<D, Ds...>
: overloads_combination_traits<Ds...> {};
template <class D, class... Ds>
requires(requires { typename D::overload_types; })
struct overloads_combination_traits<D, Ds...>
: flattening_traits<std::tuple<typename D::overload_types,
typename overloads_combination_traits<Ds...>::type>> {};

template <class... Os> requires(sizeof...(Os) > 0u)
struct dispatch_prototype { using overload_types = std::tuple<Os...>; };
template <class... Ds> requires(sizeof...(Ds) > 0u)
struct combined_dispatch_prototype : Ds... {
using overload_types = typename flattening_traits<
std::tuple<typename Ds::overload_types...>>::type;
using overload_types = typename overloads_combination_traits<Ds...>::type;
using Ds::operator()...;
};
template <class Ds = std::tuple<>, proxiable_ptr_constraints C =
Expand Down
23 changes: 23 additions & 0 deletions tests/proxy_invocation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,26 @@ TEST(ProxyInvocationTests, TestFunctionPointer) {
auto ret = p();
ASSERT_EQ(ret, (GetTypeIndices<int, double>()));
}

TEST(ProxyInvocationTests, TestCombinationWithIncompleteDispatch) {
constexpr auto not_implemented = [](auto&&...) { throw std::runtime_error{ "Not implemented!" }; };
PRO_DEF_COMBINED_DISPATCH(WeakCall, poly::Call<void()>, decltype(not_implemented));
PRO_DEF_FACADE(WeakCallable, WeakCall);
{
int side_effect = 0;
auto p = pro::make_proxy<WeakCallable>([&] { side_effect = 1; });
p();
ASSERT_EQ(side_effect, 1);
}
{
bool exception_thrown = false;
auto p = pro::make_proxy<WeakCallable>(123);
try {
p();
} catch (const std::runtime_error& e) {
exception_thrown = true;
ASSERT_EQ(static_cast<std::string>(e.what()), "Not implemented!");
}
ASSERT_TRUE(exception_thrown);
}
}

0 comments on commit 531dfcc

Please sign in to comment.