Question: I have a problem that when c++ evaluates the while statement, it also evaluates the underlying if statement even if the while statement condition is not met.

ite\_candidats is a custom iterator on a binary map tree. When there is no more nodes to visit, ite\_candidat evaluates to NULL. So the while ends. But, I get a assertion failure from ite\_candidats.clecourante() call, saying my underlying node is NULL. It shouldn't evaluate ite\_candidats.clecourante() because it wasn't meant to get to it.

I ran the program in debug mode, and !!ite\_candidats really evaluates to false when there is no more nodes to visit. If I comment out the if block, the program gets out of the while loop and everything is ok...

The operator overloading of ite\_candidats operator bool() doesn't call clecourante().

```
while(!!ite_candidats){
    if(ite_candidats.clecourante() != nompersonne){
        {...}
    }
    ite_candidats++;
}

```

Answer: 
It is impossible. If it evaluates `if` then it enters into `while`. No ahead computation is `C++`.

P.S. Why do you have two negations in `while`?
> 
> ite\_candidats is a custom iterator on a binary map tree. When there is no more nodes to visit, ite\_candidat evaluates to NULL.
> 
> 
> 

Does it really evaluate to NULL? That's a bit dubious since you are using the dot operator rather than the dereference operator in `ite_candidats.clecourante()`. From the code that you did post, it looks like `ite_candidats` is an instance of some object rather than a pointer to some object.

> 
> The operator overloading of ite\_candidats operator bool()
> 
> 
> 

This, I suspect, is the problem. Your `!!ite_candidats` is going use that conversion operator to cast `ite_candidats` to a `bool`, negate that result to yield `!ite_candidats`, then negate again to yield `!!ite_candidats`.

The problem is that your `operator bool()` is checking for a condition different from the preconditions of `WhatEverYourCustomIteratorClassIsNamed::clecourante()`.