Let's assume that I have three functions f0, f1, f2
that all take three arguments. Let's also assume that I have a big function bigFunc
to call, that takes the return values from the first three functions as arguments.
I may want to make a call like this:
bigFunc(f0(arg0, arg1, arg2), f1(arg3, arg4, arg5), f2(arg6, arg7, arg8));
This is a big call, so I think it would be far more readable to write something like this:
auto bigArg0 = f0(arg0, arg1, arg2);
auto bigArg1 = f1(arg3, arg4, arg5);
auto bigArg2 = f2(arg6, arg7, arg8);
bigFunc(bigArg0, bigArg1, bigArg2);
That's especially great if the names bigArg0, bigArg1, bigArg2
allow me to be more specific about what I am doing (for example if f0, f1, f2
are a bit generic; you can think of STL algorithms, which do different things depending of the type of iterators you give it).
The problem with this, however, is that by naming bigArg0, bigArg1, bigArg2
, I make them not to be temporaries anymore, which is (I suppose) harder for the compiler to optimize.
So, here is my question: what is the right way to do this, if I don't want to lose performance? make bigArg0, bigArg1, bigArg2
const? Give the arguments to bigFunc
through std::move
? A bit of both?