R
Rui Maciel
Ian said:Where did I say I did?
This whole discussion is about how, somehow, passing doubles as const
references don't carry a performance penalty when compared with passing them
by value, and how the only basis that has been given to substantiate that
claim was that a corner case where a specific optimization technique is used
to deal with specific functions being used a specific way is somehow
representative of how all functions are always dealt with by all C++
compilers.
Claiming that compilers are free to implemente optimization techniques on
some corner cases, such as inlining specific types of functions under
specific circumstances, says nothing about the relative efficiency of
passing doubles by value when compared to passing doubles as const
references. It only means that under a set of very specific circumstances,
which are far from being general, it's posible that a specific compiler,
when passed a specific set of options, is able to influence the inefficiency
issues associated with passing primitive types by const reference.
Hence, the weasel words bit with regards to your "most code" bit, followed
by having pointed out that inlining is far from being employed, let alone a
given.
You can only count on it if you invest your time making sure that a
specific compiler will be able to compile a specific function within
your project to match your specific requirements, but this is way past
C++'s territory and firmly within platform and
implementation-specifics.
Most C++ relies in the inlining of trivial functions, it's at the heart
of the language. Would you expect every call to std::vector's
operator[] to involve an actual call?
Trivial functions are a small subset of the whole domain of functions. A
corner case, if you will.
I don't think you can apply the term "corner case" to a large part of
the standard library!
I didn't. I'm talking about trivial functions, not specific libraries.
I'm sure no one does.
Exactly. Therefore, any claim that somehow passing doubles as const
references "does not affect performance at all" when compared to passing
them by value is simply nonsense. Which is what I have been saying.
Rui Maciel