Random access operator in MeshEntityIteratorBase modifies iterator state
Issue #484
resolved
Iterators should behave as closely as possible to pointer arithmetic, i.e.:
int * a = some pointer;
int * b = a[pos]; // does not modify a
assert(b == a+pos);
In MeshEntityIteratorBase this code:
/// Random access operator
T& operator[] (std::size_t pos)
{ _pos = pos; return *operator->();}
modifies the iterator and behaves more like this pointer operation would do:
int * a = some pointer;
a = a+pos; // modifies a
int * b = a;
This is misuse of standard operators and bug prone.
I would suggest just removing the random access operator. If it's used anywhere that code has a high chance of having bugs.
Comments (3)
-
-
- changed status to resolved
fixed by commit 247f050efc1f151f2f2c7cc2f2d19e1289dcf204
-
reporter - removed milestone
Removing milestone: 1.6 (automated comment)
- Log in to comment
We agreed before to remove the random access iterator (https://bitbucket.org/fenics-project/dolfin/issue/178), but overlooked it in
MeshEntityIteratorBase
.