aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/stl_iterators.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2019-12-03 14:40:15 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2019-12-03 14:40:15 +0100
commit7745f69013b5e4c93c1ffe6ba3173456d45c7222 (patch)
tree3ae182293e854943c393c36406676853df3de1d4 /test/stl_iterators.cpp
parent66f07efeaed39d6a67005343d7e0caf7d9eeacdb (diff)
bug #1776: fix vector-wise STL iterator's operator-> using a proxy as pointer type.
This changeset fixes also the value_type definition.
Diffstat (limited to 'test/stl_iterators.cpp')
-rw-r--r--test/stl_iterators.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/test/stl_iterators.cpp b/test/stl_iterators.cpp
index cdd9e5c33..9ede923ee 100644
--- a/test/stl_iterators.cpp
+++ b/test/stl_iterators.cpp
@@ -272,6 +272,31 @@ void test_stl_iterators(int rows=Rows, int cols=Cols)
}
}
}
+
+ {
+ // check basic for loop on vector-wise iterators
+ j=0;
+ for (auto it = A.colwise().cbegin(); it != A.colwise().cend(); ++it, ++j) {
+ VERIFY_IS_APPROX( it->coeff(0), A(0,j) );
+ VERIFY_IS_APPROX( (*it).coeff(0), A(0,j) );
+ }
+ j=0;
+ for (auto it = A.colwise().begin(); it != A.colwise().end(); ++it, ++j) {
+ (*it).coeffRef(0) = (*it).coeff(0); // compilation check
+ it->coeffRef(0) = it->coeff(0); // compilation check
+ VERIFY_IS_APPROX( it->coeff(0), A(0,j) );
+ VERIFY_IS_APPROX( (*it).coeff(0), A(0,j) );
+ }
+
+ // check valuetype gives us a copy
+ j=0;
+ for (auto it = A.colwise().cbegin(); it != A.colwise().cend(); ++it, ++j) {
+ typename decltype(it)::value_type tmp = *it;
+ VERIFY_IS_NOT_EQUAL( tmp.data() , it->data() );
+ VERIFY_IS_APPROX( tmp, A.col(j) );
+ }
+ }
+
#endif
if(rows>=3) {
@@ -410,7 +435,8 @@ void test_stl_iterators(int rows=Rows, int cols=Cols)
VectorType col = VectorType::Random(rows);
A.colwise() = col;
- VERIFY( std::all_of(A.colwise().begin(), A.colwise().end(), [&col](typename ColMatrixType::ColXpr x) { return internal::isApprox(x.norm(),col.norm()); }) );
+ VERIFY( std::all_of(A.colwise().begin(), A.colwise().end(), [&col](typename ColMatrixType::ColXpr x) { return internal::isApprox(x.norm(),col.norm()); }) );
+ VERIFY( std::all_of(A.colwise().cbegin(), A.colwise().cend(), [&col](typename ColMatrixType::ConstColXpr x) { return internal::isApprox(x.norm(),col.norm()); }) );
i = internal::random<Index>(0,A.rows()-1);
A.setRandom();