Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15228
| From | woodbrian77@gmail.com |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Default move constructor/assignment |
| Date | 2012-04-05 01:26 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <28811616.820.1333614389405.JavaMail.geo-discussion-forums@yno37> (permalink) |
| References | <4f7c129b$0$4386$7b1e8fa0@news.nbl.fi> <4f7d3aa0$0$3114$7b1e8fa0@news.nbl.fi> |
On Thursday, April 5, 2012 1:24:32 AM UTC-5, Juha Nieminen wrote: > Juha Nieminen <nospam@thanks.invalid> wrote: > > I can't find any info about this with google. > > Seemingly I have encountered such cutting-edge C++11 technology that > nobody even here seems to know the answers... :) > > Well, I'll just have to trust that clang++ is correct and > standard-conforming. Shalom The following is from Howard Hinnant in May 2011. The rules for an implicitly generated move constructor are: If the definition of a class X does not explicitly declare a move constructor, one will be implicitly declared as defaulted if and only if •X does not have a user-declared copy constructor, •X does not have a user-declared copy assignment operator, •X does not have a user-declared move assignment operator, •X does not have a user-declared destructor, and •the move constructor would not be implicitly defined as deleted. The rules for implicitly generated move assignment operators follows the pattern above. The rules for when a copy constructor is implicitly generated have changed slightly! If the class definition does not explicitly declare a copy constructor, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defined as defaulted (8.4). The latter case is deprecated if the class has a user-declared copy assignment operator or a user-declared destructor. And similarly for the copy assignment operator: If the class definition does not explicitly declare a copy assignment operator, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy assignment operator is defined as deleted; otherwise, it is defined as defaulted (8.4). The latter case is deprecated if the class has a user-declared copy constructor or a user-declared destructor. Bottom line: The rule of 3 is now the rule of 5. You can either ignore all 5 (if the default behavior works for you), or you need to think about (and likely define) all 5: 1.copy constructor 2.copy assignment 3.move constructor 4.move assignment 5.destructor ----------------------------------------------------------- I'm not sure how up to date this is. I recall Dave Abrahams commenting on this subject on cppnext also. Brian Wood Ebenezer Enterprises http://webEbenezer.net
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Default move constructor/assignment Juha Nieminen <nospam@thanks.invalid> - 2012-04-04 09:21 +0000
Re: Default move constructor/assignment Juha Nieminen <nospam@thanks.invalid> - 2012-04-05 06:24 +0000
Re: Default move constructor/assignment Miles Bader <miles@gnu.org> - 2012-04-05 16:48 +0900
Re: Default move constructor/assignment woodbrian77@gmail.com - 2012-04-05 01:26 -0700
Re: Default move constructor/assignment Juha Nieminen <nospam@thanks.invalid> - 2012-04-05 09:15 +0000
Re: Default move constructor/assignment woodbrian77@gmail.com - 2012-04-05 09:35 -0700
Re: Default move constructor/assignment Juha Nieminen <nospam@thanks.invalid> - 2012-04-06 05:29 +0000
Re: Default move constructor/assignment woodbrian77@gmail.com - 2012-04-06 23:26 -0700
Re: Default move constructor/assignment Howard Hinnant <howard.hinnant@gmail.com> - 2012-04-07 10:34 -0700
Re: Default move constructor/assignment woodbrian77@gmail.com - 2012-04-07 15:59 -0700
Re: Default move constructor/assignment woodbrian77@gmail.com - 2012-04-07 18:58 -0700
Re: Default move constructor/assignment SG <s.gesemann@gmail.com> - 2012-04-10 02:21 -0700
csiph-web