[Networkit] const and non-const iterator methods in Graph
Marvin Ritter
marvin.ritter at gmail.com
Wed May 14 12:37:34 CEST 2014
Hi,
I have a short question regarding the iterator methods in the Graph class.
There are all those nice methods called forNodes, forEdges, forEdgesOf ...
and for all of them there are 2 definition, one normal one and another
const one.
I really like the use of const, but hy do we need the non-const versions??
All those iterator methods, do not change the graph, they just loop over
something.
So what happens if we remove the non-const versions? So that we only have
Graph.forNodes(L handle) const;
but not
Graph.forNodes(L handle);
Then we still could do the following:
Graph G(3);
G.forNodes([&](node v) { // we will use the const version of forNodes,
because it is the only version available and non-const instances can use
the const methods as well
if (v == 2) G.addNode(); // forNodes is const, but we use our G which isn't
so we can still change G
});
const Graph T(3);
T.forNodes([&](node v) { // we use the const version of forNodes
if (v == 2) T.addNode(); // would not work because T is const and addNode
isn't
});
So what case did I miss where we need the non-const version of forNodes?
Thanks and best regards,
Marvin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ira.uni-karlsruhe.de/mailman/private/networkit/attachments/20140514/2dc4ecad/attachment.html>
More information about the NetworKit
mailing list