Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce compile-time complexity of combined_dispatch_prototype::overload_types #60

Merged
merged 2 commits into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 21 additions & 30 deletions proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,46 +598,37 @@ struct overloads_matching_traits<std::tuple<Args...>, std::tuple<Os...>>
template <class Args, class Os>
concept matches_overloads = overloads_matching_traits<Args, Os>::applicable;

template <class T, class U> struct flattening_traits_impl;
template <class T>
struct flattening_traits_impl<std::tuple<>, T> { using type = T; };
template <class T, class... Ts, class U>
struct flattening_traits_impl<std::tuple<T, Ts...>, U>
: flattening_traits_impl<std::tuple<Ts...>, U> {};
template <class T, class... Ts, class... Us>
requires(!contains_traits<T, Us...>::applicable)
struct flattening_traits_impl<std::tuple<T, Ts...>, std::tuple<Us...>>
: flattening_traits_impl<std::tuple<Ts...>, std::tuple<Us..., T>> {};
template <class T> struct flattening_traits { using type = std::tuple<T>; };
template <>
struct flattening_traits<std::tuple<>> { using type = std::tuple<>; };
template <class T, class... Ts>
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 T> struct final_reduction { using type = T; };
template <template <class, class> class R, class O, class... Is>
struct recursive_reduction : final_reduction<O> {};
template <template <class, class> class R, class O, class I, class... Is>
struct recursive_reduction<R, O, I, Is...>
: recursive_reduction<R, typename R<O, I>::type, Is...> {};

template <class O, class I> struct flat_reduction : final_reduction<O> {};
template <class... Os, class I> requires(!contains_traits<I, Os...>::applicable)
struct flat_reduction<std::tuple<Os...>, I>
: final_reduction<std::tuple<Os..., I>> {};
template <class... Os, class... Is>
struct flat_reduction<std::tuple<Os...>, std::tuple<Is...>>
: recursive_reduction<flat_reduction, std::tuple<Os...>, Is...> {};
template <class O, class I> struct overloads_reduction : final_reduction<O> {};
template <class O, class I> requires(requires { typename I::overload_types; })
struct overloads_reduction<O, I>
: flat_reduction<O, typename I::overload_types> {};

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 overloads_combination_traits<Ds...>::type;
using overload_types = typename recursive_reduction<
overloads_reduction, std::tuple<>, Ds...>::type;
using Ds::operator()...;
};
template <class Ds = std::tuple<>, proxiable_ptr_constraints C =
relocatable_ptr_constraints, class R = void>
struct facade_prototype {
using dispatch_types = typename flattening_traits<Ds>::type;
using dispatch_types = typename flat_reduction<std::tuple<>, Ds>::type;
static constexpr proxiable_ptr_constraints constraints = C;
using reflection_type = R;
};
Expand Down