Is putting a function within an if statement efficient? (C++)
c++, performance
Solution
I'm not sure what makes you think that assigning the result of the expression to a variable first would be more efficient than evaluating the expression itself, but it's never going to matter, so choose the option that enhances the readability of your code. If you really want to know, look at the output of your compiler and see if there is any difference. On the vast majority of systems out there this will likely result in identical machine code.
Problem
I've seen statements like this ``` if(SomeBoolReturningFunc()) { //do some stuff //do some more stuff } ``` and am wondering if putting a function in an if statement is efficient, or if there are cases when it would be better to leave them separate, like this ``` bool AwesomeResult = SomeBoolReturningFunc(); if(AwesomeResult) { //do some other, more important stuff } ``` ...?