Why would the implicitly generated constructor (et al.) be more efficient than a user-defined (trivial) one?

前端 未结 4 1227
梦毁少年i
梦毁少年i 2020-12-20 13:04

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:

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-20 13:55

    You ask, how is it that

    class C { C() = default; };
    

    can be more efficient than

    class C { C(){} };
    

    Well, both constructors do nothing, so it's meaningless to talk about efficiency for that example.

    But more generally, in e.g. a copy constructor one can imagine that copying one POD item at a time will not be recognized as optimizable by simple optimizer, whereas with automatic generation it might just do a memcpy. Who knows. It's a Quality of Implementation issue, and I can easily imagine also the opposite.

    So, measure, if it matters.

    Cheers & hth.,

提交回复
热议问题