I am currently doing:
if constexpr(constexpr_bool_var1) {
auto arg1 = costly_arg1(); auto arg2 = costly_arg2();
if (costly_runtime_function(arg1, arg2)) {
}
} else {
}
One possible way is to convert do X / Y, etc. into one doXY () function and calling it in both places, however it seems very cumbersome because I have to write a function that exists only for the convenience of metaprogramming.
I want something like:
if not constexpr(constexpr_bool_var1 && some_magic(costly_runtime_function(arg1, arg2)) {
// do X, do Y
}
Another way:
auto arg1 = costly_arg1();
auto arg2 = costly_arg2();
if (constexpr_bool_var1 && costly_runtime_function(arg1, arg2)) {
} else {
}
However, here arg1 and arg2 are declared outside the if condition, so they will be uselessly created.
source
share