Skip to content

Commit 1b40e95

Browse files
authored
Merge pull request #130 from SimonRohou/codac2_dev
[mat] corrected iterator
2 parents db15ee8 + a59fe93 commit 1b40e95

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

python/src/core/matrices/codac2_py_VectorBase.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ void export_VectorBase(py::module& m, py::class_<S>& pyclass)
101101

102102
.def("__iter__", [](const S &x)
103103
{
104-
auto x_ = x._e.reshaped();
105-
return py::make_iterator(x_.begin(), x_.end());
104+
return py::make_iterator(x._e.begin(), x._e.end());
106105
},
107106
py::keep_alive<0, 1>() /* keep object alive while iterator exists */)
108107
;

src/core/matrices/codac2_MatrixBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ namespace codac2
298298

299299
iterator begin()
300300
{
301-
return const_cast<iterator>(const_cast<const MatrixBase<S,T,Rows,Cols>*>(this)->begin());
301+
return _e.begin();
302302
}
303303

304304
const_iterator begin() const
@@ -313,7 +313,7 @@ namespace codac2
313313

314314
iterator end()
315315
{
316-
return const_cast<iterator>(const_cast<const MatrixBase<S,T,Rows,Cols>*>(this)->end());
316+
return _e.end();
317317
}
318318

319319
EigenType _e;

tests/core/matrices/codac2_tests_Vector.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ using namespace codac2;
1616

1717
TEST_CASE("Vector")
1818
{
19-
19+
size_t i = 0;
20+
Vector a(3), b {{-1},{2},{-3}};
21+
for(const auto& bi : b)
22+
a[i++] = bi;
23+
CHECK(a == b);
2024
}

0 commit comments

Comments
 (0)