@@ -12,20 +12,26 @@ namespace elasticapp {
1212// Generic helpers for computing variable offsets in any System
1313
1414// Helper to find the index of a type in a parameter pack
15+ template <typename Target, std::size_t CurrentIndex, typename ... Ts>
16+ struct find_index_impl ; // Forward declaration
17+
18+ // Found the type
19+ template <typename Target, std::size_t CurrentIndex, typename ... Rest>
20+ struct find_index_impl <Target, CurrentIndex, Target, Rest...> {
21+ static constexpr std::size_t value = CurrentIndex;
22+ };
23+
24+ // Recurse to the next type in the pack
1525template <typename Target, std::size_t CurrentIndex, typename First, typename ... Rest>
16- struct find_index_impl {
17- using type = std::conditional_t <
18- std::is_same_v<Target, First>,
19- std::integral_constant<std::size_t , CurrentIndex>,
20- find_index_impl<Target, CurrentIndex + 1 , Rest...>
21- >;
22- static constexpr std::size_t value = type::value;
26+ struct find_index_impl <Target, CurrentIndex, First, Rest...> {
27+ static constexpr std::size_t value = find_index_impl<Target, CurrentIndex + 1 , Rest...>::value;
2328};
2429
25- // Base case: when Target matches First (Rest may be empty)
30+ // Type not found in the pack (empty pack) - this provides a clear error message
2631template <typename Target, std::size_t CurrentIndex>
27- struct find_index_impl <Target, CurrentIndex, Target> {
28- static constexpr std::size_t value = CurrentIndex;
32+ struct find_index_impl <Target, CurrentIndex> {
33+ static_assert (dependent_false<Target>::value,
34+ " Undefined variable requested. Please ensure the variable is defined in the System's variable list." );
2935};
3036
3137// Helper to sum dimensions of variables up to (but not including) a given index
0 commit comments