I would say, in addition to the answer, that "yes, this is guaranteed by the C ++ standard":
Please use the first form. It is much clearer what you are trying to achieve.
I can almost guarantee that any sane compiler (with a minimal amount of optimization) will in any case generate exactly the same code for both examples.
Therefore, while it is useful to know that both of these forms achieve the same “protection,” it is definitely preferable to use the form that is most readable.
It also means that you don’t need to write a comment explaining that it is safe because of a paragraph of the same in the C ++ standard, thereby making both occupy the same amount of code space, because if you didn’t do this, know it earlier, then you can rely on someone else, not knowing that it is safe, and then spend the next half hour to find the answer via google and either run into this thread or ask a question again!
source share