S
samuel.y.l.cheung
Hi,
I am trying to convert a Java iterator loop to C++ STL? the loop looks
like this:
public static boolean func (List aList) {
int minX = 0
for (Iterator iter = aList.listIterator(1); iter.hasNext() {
A a = (A) iter.next();
if (! closeEnough(minX, a.x) ) {
return true;
} else {
minX = a.x;
}
}
return false;
}
I am reading the "Effecitive STL" book, it said i should use STL
algorithm instead of writing my loop if possible. I was thinking of
using for_each(). But in this case, i need to update a local variable
'minX' and stop the iteration if certain condition is met. Should I
use for_each()? or I write my own iterator loop?
Thank you for any idea.
I am trying to convert a Java iterator loop to C++ STL? the loop looks
like this:
public static boolean func (List aList) {
int minX = 0
for (Iterator iter = aList.listIterator(1); iter.hasNext() {
A a = (A) iter.next();
if (! closeEnough(minX, a.x) ) {
return true;
} else {
minX = a.x;
}
}
return false;
}
I am reading the "Effecitive STL" book, it said i should use STL
algorithm instead of writing my loop if possible. I was thinking of
using for_each(). But in this case, i need to update a local variable
'minX' and stop the iteration if certain condition is met. Should I
use for_each()? or I write my own iterator loop?
Thank you for any idea.