Skip to content

Commit

Permalink
Reduce compile-time complexity of combined_dispatch_prototype::overlo…
Browse files Browse the repository at this point in the history
…ad_types (#60)

* Reduce compile-time complexity of combined_dispatch_prototype::overload_types from O(n^3) to O(n^2)

* Refactor
  • Loading branch information
mingxwa authored Jan 18, 2024
1 parent deee3c6 commit baa0f87
Showing 1 changed file with 21 additions and 30 deletions.
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

0 comments on commit baa0f87

Please sign in to comment.