I have a function f(int x, float y, char* z, .., bool b)
. The argument b
is used only in the fashion of:
if (b) {
...
} else {
...
}
in various parts of the function body. For efficiency reason, I would like to effectively create two functions f0
and f1
, where b
is set to false
and true
respectively, to avoid evaluating the conditional at run time. At the same time since the implementation of f
is fairly long, I don't want to explicitly define f0
and f1
separately. Is there any compiler optimization feature that automatically spawns these two branch functions at compile time?
Maybe there are better design patterns that avoid this line of thinking completely? Keep in mind that the conditional b
can be evaluated in a massive loop.