Add C++17 structured bindings support for fixed-size Matrix and Array
Summary
- Specialize
std::tuple_sizeandstd::tuple_elementfor fixed-sizeMatrixandArraytypes - Provide
Eigen::get<Idx>()free functions found via ADL - Guarded by
EIGEN_MAX_CPP_VER >= 17 && EIGEN_COMP_CXXVER >= 17
Usage
Eigen::Vector3d v(1, 2, 3);
auto [x, y, z] = v; // by-value decomposition
auto& [rx, ry, rz] = v; // by-reference (mutation possible)
Eigen::Array3i a(4, 5, 6);
auto [a0, a1, a2] = a; // works for Array too
Eigen::Matrix2d m;
m << 1, 2, 3, 4;
auto [m00, m10, m01, m11] = m; // column-major order
Test plan
- Vector2, Vector3, Vector4 by-value decomposition (double, float, int)
- Array2, Array3 by-value decomposition
- Mutable reference binding (mutation through binding modifies original)
- Const reference binding
- Matrix2d decomposition (column-major order)
- 1x1 matrix edge case
- RowVector decomposition
- Static checks for tuple_size and tuple_element
- All existing tests pass
Closes #2247 (closed)