Given the following: auto x = Eigen::ArrayXXd(2, 3); x << 0.0, 1.0, 2.0, 3.0, 4.0, 5.0; for (auto it = x.colwise().cbegin(); it != x.colwise().cend(); ++it) std::cout << "x = " << it->coeff(0) << '\n'; GCC 9.2.1 reports: .../src/Core/StlIterators.h:254:48: error: taking address of rvalue [-fpermissive] No such warning is triggered if we use operator* instead: std::cout << "x = " << (*it).coeff(0) << '\n'; as would be done implicitly if we were to use range-based for.
Indeed. Another failure case is: auto x = Eigen::ArrayXXcd(2, 3); auto xpr = 2*x.col(0); for (auto it = xpr.cbegin(); it != xpr.cend(); ++it) std::cout << "x = " << it->real() << '\n'; I'm not sure how to fix this issue though.
I found a possible fix through a proxy, within the body of subvector_stl_iterator: typedef typename internal::conditional<bool(is_lvalue), SubVectorType, ConstSubVectorType>::type value_type; typedef value_type reference; private: struct subvector_stl_iterator_ptr { subvector_stl_iterator_ptr(value_type& a) : m_subvec(a) {} value_type* operator->() { return &m_subvec; } private: value_type m_subvec; }; public: typedef subvector_stl_iterator_ptr pointer; pointer operator->() const { return ((*mp_xpr).template subVector<Direction>(m_index)); }
I think `value_type` should actually be `SubVectorType::PlainObject`, and `reference` what currently is `value_type` (`subvector_stl_iterator_ptr` needs to contain a `reference` of course). operator->() could just `return pointer(operator*());`
Make sense!
https://bitbucket.org/eigen/eigen/commits/44810c827c77/ Summary: Bug 1776: fix vector-wise STL iterator's operator-> using a proxy as pointer type. This changeset fixes also the value_type definition.
-- GitLab Migration Automatic Message -- This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1776.