The Named Parameter Idiom as described here mentions that there will be a performance impact when not using
Since each member function in the chain returns a reference, there is no copying of objects and the chain is highly efficient. Furthermore, if the various member functions are inline, the generated object code will probably be on par with C-style code that sets various members of a struct. Of course if the member functions are not inline, there may be a slight increase in code size and a slight decrease in performance (but only if the construction occurs on the critical path of a CPU-bound program; this is a can of worms I’ll try to avoid opening), so it may, in this case, be a tradeoff for making the code more reliable.
Does this still hold true in spite of modern compilers and using
-O2 when compiling? I was under the impression, that modern compilers will generally inline on their own (especially with -O2) when they see a possible benefit. In addition the
inline keyword is little more than a hint to the compiler and by no means forces the inlining.