I read this article from D. Kalev this morning about the new c++11 feature "defaulted and deleted functions", and can't understand the part about performance, namely:
the manual definition of a special member function (even if it's trivial) is usually less efficient than an implicitly-defined one.
By googling to find an answer, I found another article of the same author:
the synthesized constructor and copy constructor enable the implementation to create code that's more efficient than user-written code, because it can apply optimizations that aren't always possible otherwise.
There is no explication, but I read time to time similar claims.
But how is it that writing:
class C { C() = default; };
can be more efficient than
class C { C(){} };
? I though a compiler would be smart enough to detect such situation and optimize that. In other words how is it easier for the compiler to optimize when it sees =default
instead of {}
(void body function)?
Edit: the question was edited to add the "c++11" tag, but this question remains in c++03 context: just replace class C {C()=default;};
by class C {};
, so not really a c++11 specific question.