I have a relatively simple algorithm that walks an std::vector looking for two neighbouring tuples. Once the tuples left and right of the X value are found I can interpolate between them. Somehow this works:
std::vector<LutTuple*>::iterator tuple_it;
LutTuple* left = NULL;
LutTuple* right = NULL;
bool found = 0;
// Only iterate as long as the points are not found
for(tuple_it = lut.begin(); (tuple_it != lut.end() && !found); tuple_it++) {
// If the tuple is less than r2 we found the first element
if((*tuple_it)->r < r) {
left = *tuple_it;
}
if ((*tuple_it)->r > r) {
right = *tuple_it;
}
if(left && right) {
found = 1;
}
}
while this:
std::vector<LutTuple*>::iterator tuple_it;
LutTuple* left = NULL;
LutTuple* right = NULL;
// Only iterate as long as the points are not found
for(tuple_it = lut.begin(); tuple_it != lut.end() && !left && !right; tuple_it++) {
// If the tuple is less than r2 we found the first element
if((*tuple_it)->r < r) {
left = *tuple_it;
}
if ((*tuple_it)->r > r) {
right = *tuple_it;
}
}
does not. Why is that? I'd expect two NULL ptrs like this to evaluate to true together when negated.