From 05f7cdc9ea6a30a371d5954c6316757742cf5fbd Mon Sep 17 00:00:00 2001 From: Bogdan Burlacu Date: Sat, 13 Apr 2024 18:28:25 +0200 Subject: [PATCH] dispatch table: work around gcc bug --- include/operon/interpreter/dispatch_table.hpp | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/include/operon/interpreter/dispatch_table.hpp b/include/operon/interpreter/dispatch_table.hpp index 312eda0..d13faac 100644 --- a/include/operon/interpreter/dispatch_table.hpp +++ b/include/operon/interpreter/dispatch_table.hpp @@ -108,7 +108,7 @@ struct Noop { template static inline void DiffOp(Operon::Vector const& nodes, Backend::View primal, Backend::View trace, int i, int j) { Diff{}(nodes, primal, trace, i, j); -}; +} template static constexpr auto MakeFunctionCall() -> Dispatch::Callable @@ -151,6 +151,17 @@ namespace detail { { T::size() }; { std::is_array_v }; }; + + template + struct ExtractTypes { + static auto constexpr Extract() { + return [](std::index_sequence){ + return std::make_tuple(std::tuple_element_t{}...); + }(std::make_index_sequence{}); + } + + using Type = decltype(Extract()); + }; } // namespace detail template @@ -158,14 +169,11 @@ struct DispatchTable { private: using Tup = std::tuple; // make the type parameters into a tuple + static auto constexpr N = std::tuple_size_v; // retrieve the last type in the template parameter pack - using Lst = std::tuple_element_t; - - using Typ = std::conditional_t, decltype([](std::index_sequence){ - return std::make_tuple(std::tuple_element_t{}...); - }(std::make_index_sequence{})), Tup>; - + using Lst = std::tuple_element_t; + using Typ = std::conditional_t, typename detail::ExtractTypes::Type, Tup>; using Ext = std::conditional_t, Lst, std::index_sequence...>>; template> @@ -193,12 +201,12 @@ struct DispatchTable { template static constexpr auto MakeFunction() { return Dispatch::MakeFunctionCall>(); - }; + } template static constexpr auto MakeDerivative() { return Dispatch::MakeDiffCall>(); - }; + } template static constexpr auto MakeTuple() @@ -209,7 +217,7 @@ struct DispatchTable { std::make_tuple(MakeDerivative>()...) ); }(std::index_sequence_for{}); - }; + } using TFun = decltype([](std::index_sequence){ return std::make_tuple(Callable>{}...);