diff --git a/include/glaze/concepts/container_concepts.hpp b/include/glaze/concepts/container_concepts.hpp index e8361d97d0..97e2faa1b4 100644 --- a/include/glaze/concepts/container_concepts.hpp +++ b/include/glaze/concepts/container_concepts.hpp @@ -265,20 +265,36 @@ namespace glz requires std::input_iterator; }; + // Concept for a matrix type (not a vector, which is a range) template concept matrix_t = requires(T matrix) { matrix.resize(2, 4); matrix.data(); { matrix.rows() - } -> std::convertible_to; + } -> std::convertible_to; { matrix.cols() - } -> std::convertible_to; + } -> std::convertible_to; { matrix.size() - } -> std::convertible_to; + } -> std::convertible_to; } && !range; + + // concept for the Eigen library: matrices and vectors + template + concept eigen_t = requires(T matrix) { + matrix.data(); + { + matrix.rows() + } -> std::convertible_to; + { + matrix.cols() + } -> std::convertible_to; + { + matrix.size() + } -> std::convertible_to; + }; // range like template diff --git a/include/glaze/core/common.hpp b/include/glaze/core/common.hpp index 85aed58c97..038c2fd410 100644 --- a/include/glaze/core/common.hpp +++ b/include/glaze/core/common.hpp @@ -454,7 +454,7 @@ namespace glz else if constexpr (std::is_member_function_pointer_v) { return element; } - else if constexpr (std::invocable && not matrix_t) { + else if constexpr (std::invocable && not eigen_t) { // Eigen places a static_assert inside of the operator()(), so we must target // matrix types and reject them from the invocable check // Eigen ought to put the check in the `enable_if` for operator()() diff --git a/tests/eigen_test/eigen_test.cpp b/tests/eigen_test/eigen_test.cpp index 473a51e9f6..8d8fbcaf9d 100644 --- a/tests/eigen_test/eigen_test.cpp +++ b/tests/eigen_test/eigen_test.cpp @@ -45,12 +45,8 @@ struct complex_struct Eigen::MatrixXcd mcd; } complex_test_value; -template <> -struct glz::meta -{ - using T = complex_struct; - static constexpr auto value = object(&T::mf, &T::vi, &T::mcd); -}; +static_assert(glz::eigen_t); +static_assert(glz::eigen_t); // Initialize complex_test_value void initialize_complex_struct()