Skip to content

Commit 68e8f61

Browse files
committed
reduce variadic error message
1 parent 2ce0f56 commit 68e8f61

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

backend/src/traits.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <Eigen/Dense>
44
#include <cstddef>
5+
#include <type_traits>
56

67
namespace elasticapp {
78

@@ -11,6 +12,10 @@ using IndexType = Eigen::Index;
1112
constexpr bool IsRowMajor = true;
1213
constexpr bool IsColMajor = false;
1314

15+
// Helper for static_asserts in templates
16+
template<typename T>
17+
struct dependent_false : std::false_type {};
18+
1419
// Helper functions for computing strides for numpy array views
1520
inline std::pair<ptrdiff_t, ptrdiff_t> compute_strides(std::size_t rows, std::size_t cols) {
1621
if constexpr (IsRowMajor) {

backend/src/variable_offsets.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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
1525
template<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
2631
template<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

Comments
 (0)