Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Move semantics and ctor

42 views
Skip to first unread message

AP

unread,
Sep 20, 2014, 10:50:58 PM9/20/14
to
When should one consider implementing a an explicit move ctor (such as Class::Class(const Class&&) ) ?
Thank you in advance !

Ian Collins

unread,
Sep 21, 2014, 1:20:22 AM9/21/14
to
AP wrote:
> When should one consider implementing a an explicit move ctor (such
> as Class::Class(const Class&&) ) ? Thank you in advance !

Without the const... When the const of copying the class makes a move
constructor worth while.

--
Ian Collins

Chris Vine

unread,
Sep 21, 2014, 4:40:03 AM9/21/14
to
That is not a move constructor. It is a copy constructor for immutable
rvalues. I cannot think of any case where one would want to consider
implementing one of those.

You would consider implementing a move constructor where there is an
efficiency advantage to be obtained by moving the internals of a mutable
rvalue (such as a temporary) instead of copying it.

Chris

Öö Tiib

unread,
Sep 21, 2014, 11:56:45 AM9/21/14
to
On Sunday, 21 September 2014 05:50:58 UTC+3, AP wrote:
> When should one consider implementing a an explicit move ctor (such as Class::Class(const Class&&) ) ?
>
> Thank you in advance !

This article
http://flamingdangerzone.com/cxx11/2012/08/15/rule-of-zero.html
elaborates some things about those special functions
quite nicely.
0 new messages