c ++ – What is the "best" way to create a branch on a two-state enum?

The best solution for me is missing here: switch:

switch (state)
{
Condition of case :: first:
// do something
Pause;
State of the case :: second:
// do something else
}

Why is it better?

Readability: Reading this, it is clear what will happen in which case. Compared to everything if not you do not need to know which states are actually available because they are all explicitly listed.

In addition, the other some of your versions // 0 and // 1 Do not really state your intention. As they are, they are content to say, "All that is not State :: first", while you mean" The other a part concerns State :: second. Even when adding later a third state that will do exactly the same as the second, adding Case Status :: Third just between State of the case :: second: and // do something else makes absolutely understand what we hear with this piece of code. Leave this in silence to be treated by other introduces unnecessary complications when reading the code.

maintainability: Sooner or later, you might consider having a third state. Then, most modern compilers will warn you of the absence of this case inside the switch statement (if you do not add any fault case you should not). It's impossible for everything if not construction.

Performance: A switch statement can be compiled into an efficient jmp table, while in the worst case if-else-cascades will have to be covered until their end, by comparing the value of State again and again. This is not too problematic for a two-state enum, however.