Topic: Shortcuts for default/delete of special member functions.
Author: Benjamin Lindley <benjameslindley@gmail.com>
Date: Sun, 4 Jan 2015 14:14:57 -0800 (PST)
Raw View
------=_Part_188_757899153.1420409697342
Content-Type: multipart/alternative;
boundary="----=_Part_189_1285554114.1420409697342"
------=_Part_189_1285554114.1420409697342
Content-Type: text/plain; charset=UTF-8
I think most people would agree that being explicit about what code should
or shouldn't be automatically generated is a good thing. However, this:
Bar() = default;
Bar(Bar const&) = default;
Bar(Bar&&) = default;
Bar& operator=(Bar const&) = default;
Bar& operator=(Bar&&) = default;
~Bar() = default;
is a lot of noise for something that is going to happen anyway if I simply
type nothing. I suggest a shortcut syntax. First, for individual members:
default default_ctor; // generate default constructor
default copy_ctor; // generate copy constructor
default move_ctor; // generate move constructor
default copy_assign; // generate copy assignment operator
default move_assign; // generate move assignment operator
default dtor; // generate destructor
default virtual_dtor; // generate virtual destructor
By itself, that doesn't save much, but (imo) it is easier to read. Now, we
can combine multiple declarations, e.g.
default move_ctor, move_assign, default_ctor, dtor;
The above would be equivalent to the following:
default move_ctor;
default move_assign;
default default_ctor;
default dtor;
And finally, we can combine common selections into one:
default copy; // copy constructor and copy assignment
operator
default move; // move constructor and move assignment
operator
default all; // all special member functions.
That last one (all), I would say, is of questionable value, because it
could have undesirable effects if other special member functions are added
in the future. But even without it, an explicit default definition of all
special member functions is quite simple:
default copy, move, default_ctor, dtor;
delete can be used the same way. Functions which are commonly deleted are
the copy constructor, copy assignment operator, and default constructor,
which can all be achieved as follows:
delete copy, default_ctor;
Thank you for your feedback.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_189_1285554114.1420409697342
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I think most people would agree that being explicit about =
what code should or shouldn't be automatically generated is a good thing. H=
owever, this:<br><br><div class=3D"prettyprint" style=3D"background-color: =
rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; =
border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div=
class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #606;" class=3D"styled-=
by-prettify">Bar</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">default</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Bar</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #606;=
" class=3D"styled-by-prettify">Bar</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">const</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&)</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">default</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br> </span><span =
style=3D"color: #606;" class=3D"styled-by-prettify">Bar</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #606;" class=3D"styled-by-prettify">Bar</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&&)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">default</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
</span><span style=3D"color: #606;" class=3D"styled-by-pretti=
fy">Bar</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">operator</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">=3D(</span><span st=
yle=3D"color: #606;" class=3D"styled-by-prettify">Bar</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">const</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&)</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
default</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br> &=
nbsp; </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Bar<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D(</span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Bar</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&&)</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">default</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">~</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Ba=
r</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">default</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">;</span></div></code></div><br>is a lot of no=
ise for something that is going to happen anyway if I simply type nothing. =
I suggest a shortcut syntax. First, for individual members:<br><br><div cla=
ss=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-co=
lor: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap:=
break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">default</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> default_ctor</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #800;" class=3D"styled-by-prettify">// generate default c=
onstructor</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">default</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> copy_ctor</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> &nb=
sp; </span><span style=3D"color: #800;" class=3D"styled-by-pr=
ettify">// generate copy constructor</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">default</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> move_ctor</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: =
#800;" class=3D"styled-by-prettify">// generate move constructor</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">default</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> copy_assign</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #800;" class=3D"styled-by-prettify">// generate copy a=
ssignment operator</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">default</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> move_assign</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #800;" class=3D"styled-by=
-prettify">// generate move assignment operator</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"><br> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">default</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> dtor</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #800;" class=3D"styled-by-prettify">// generate d=
estructor</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">default</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> virtual_dtor</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> &=
nbsp; </span><span style=3D"color: #800;" class=3D"styled-by-prettify=
">// generate virtual destructor</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span></div></code></div><br>By itself, that d=
oesn't save much, but (imo) it is easier to read. Now, we can combine multi=
ple declarations, e.g.<br><br><div class=3D"prettyprint" style=3D"backgroun=
d-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style=
: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"prettypr=
int"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">default</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> move_ctor</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> move_assign</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> default_ctor</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
dtor</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></di=
v></code></div><br>The above would be equivalent to the following:<br><br><=
div class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bo=
rder-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; wor=
d-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettypri=
nt"><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">default</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> move_ctor</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">default</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> move_assign</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">default</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> default_ctor</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br> </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">default</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> dtor</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">;</span></div></code></d=
iv><br>And finally, we can combine common selections into one:<br><br><div =
class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border=
-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wr=
ap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">default</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> copy</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #800;" class=3D"styled-by-pretti=
fy">// copy constructor and copy assignment operator</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br> </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">default</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> move</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #800;" class=3D"styled-by-prettify">// move co=
nstructor and move assignment operator &=
nbsp; =
</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">default</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> all</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #800;" class=3D"styled-by-prettify">// all specia=
l member functions.</span></div></code></div><br>That last one (all), I wou=
ld say, is of questionable value, because it could have undesirable effects=
if other special member functions are added in the future. But even withou=
t it, an explicit default definition of all special member functions is qui=
te simple:<br><br><div class=3D"prettyprint" style=3D"background-color: rgb=
(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bor=
der-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div cl=
ass=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">default</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> copy</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> move</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> default_ctor</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> dtor</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span></div></code></div><br>delete =
can be used the same way. Functions which are commonly deleted are the copy=
constructor, copy assignment operator, and default constructor, which can =
all be achieved as follows:<br><br><div class=3D"prettyprint" style=3D"back=
ground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-=
style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pre=
ttyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">delete</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> copy</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> default_ctor</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span></div></code></div><br>Thank you for your feedback.<br></div=
>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_189_1285554114.1420409697342--
------=_Part_188_757899153.1420409697342--
.
Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Mon, 5 Jan 2015 08:26:04 +0000
Raw View
Would default all generate a virtual dtor or non-virtual? What about
default assign for copy & move assignments?
On 1/4/15, Benjamin Lindley <benjameslindley@gmail.com> wrote:
> I think most people would agree that being explicit about what code should
> or shouldn't be automatically generated is a good thing. However, this:
>
> Bar() = default;
> Bar(Bar const&) = default;
> Bar(Bar&&) = default;
> Bar& operator=(Bar const&) = default;
> Bar& operator=(Bar&&) = default;
> ~Bar() = default;
>
> is a lot of noise for something that is going to happen anyway if I simply
> type nothing. I suggest a shortcut syntax. First, for individual members:
>
> default default_ctor; // generate default constructor
> default copy_ctor; // generate copy constructor
> default move_ctor; // generate move constructor
> default copy_assign; // generate copy assignment operator
> default move_assign; // generate move assignment operator
> default dtor; // generate destructor
> default virtual_dtor; // generate virtual destructor
>
> By itself, that doesn't save much, but (imo) it is easier to read. Now, we
> can combine multiple declarations, e.g.
>
> default move_ctor, move_assign, default_ctor, dtor;
>
> The above would be equivalent to the following:
>
> default move_ctor;
> default move_assign;
> default default_ctor;
> default dtor;
>
> And finally, we can combine common selections into one:
>
> default copy; // copy constructor and copy assignment
> operator
> default move; // move constructor and move assignment
> operator
> default all; // all special member functions.
>
> That last one (all), I would say, is of questionable value, because it
> could have undesirable effects if other special member functions are added
> in the future. But even without it, an explicit default definition of all
> special member functions is quite simple:
>
> default copy, move, default_ctor, dtor;
>
> delete can be used the same way. Functions which are commonly deleted are
> the copy constructor, copy assignment operator, and default constructor,
> which can all be achieved as follows:
>
> delete copy, default_ctor;
>
> Thank you for your feedback.
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.
Author: David Krauss <potswa@gmail.com>
Date: Mon, 5 Jan 2015 18:00:01 +0800
Raw View
--Apple-Mail=_B39706FC-7C50-45F4-AB61-13FE2DB9BAB1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
> On 2015=E2=80=9301=E2=80=9305, at 4:26 PM, Douglas Boffey <douglas.boffey=
@gmail.com> wrote:
>=20
> Would default all generate a virtual dtor or non-virtual? What about
> default assign for copy & move assignments?
One alternative to explicitly deleting/defaulting is to inherit from a base=
class (or several).
struct movable {
movable( movable && ) =3D default;
movable( movable const & ) =3D delete; // Derived class is not copyable=
..
movable & operator =3D ( movable && ) =3D default;
movable & operator =3D ( movable const & ) =3D delete;
};
struct copyable {
// Declare default members if you like.
};
struct polymorphic {
virtual ~ polymorphic() =3D default;
};
Note, such classes should only be used with private inheritance. As public =
bases they create potential dynamic =E2=80=9Csibling=E2=80=9D casts, which =
bloats RTTI.
This covers most of the use-cases with equal terseness, but not default def=
ault_ctor;. I think that the default constructor belongs with the rest of t=
he constructors anyway.
(I=E2=80=99m not endorsing such usage, I=E2=80=99m just pointing out the po=
ssibility.)
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.
--Apple-Mail=_B39706FC-7C50-45F4-AB61-13FE2DB9BAB1
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9301=
=E2=80=9305, at 4:26 PM, Douglas Boffey <<a href=3D"mailto:douglas.boffe=
y@gmail.com" class=3D"">douglas.boffey@gmail.com</a>> wrote:</div><br cl=
ass=3D"Apple-interchange-newline"><div class=3D"">Would default all generat=
e a virtual dtor or non-virtual? What about<br class=3D"">default ass=
ign for copy & move assignments?<br class=3D""></div></blockquote></div=
><br class=3D""><div class=3D"">One alternative to explicitly deleting/defa=
ulting is to inherit from a base class (or several).</div><div class=3D""><=
br class=3D""></div><div class=3D""><span style=3D"font-family: Courier;" c=
lass=3D"">struct movable {</span></div><div class=3D""><font face=3D"Courie=
r" class=3D""> movable( movable && ) =3D default;</fon=
t></div><div class=3D""><font face=3D"Courier" class=3D""> mov=
able( movable const & ) =3D delete; // Derived class is not copyable.</=
font></div><div class=3D""><font face=3D"Courier" class=3D""><br class=3D""=
></font></div><div class=3D""><font face=3D"Courier" class=3D""> &nbs=
p; movable & operator =3D </font><span style=3D"font-family: Couri=
er;" class=3D"">( movable && ) =3D default;</span></div><div class=
=3D""><span style=3D"font-family: Courier;" class=3D""> <=
/span><span style=3D"font-family: Courier;" class=3D"">movable & operat=
or =3D </span><span style=3D"font-family: Courier;" class=3D"">( movab=
le const & ) =3D delete;</span></div><div class=3D""><font face=3D"Cour=
ier" class=3D"">};</font></div><div class=3D""><div class=3D""><font face=
=3D"Courier" class=3D""><br class=3D""></font></div><div class=3D""><font f=
ace=3D"Courier" class=3D"">struct copyable {</font></div><div class=3D""><f=
ont face=3D"Courier" class=3D""> // </font><span style=3D=
"font-family: Courier;" class=3D"">Declare default members if you like.</sp=
an></div><div class=3D""><font face=3D"Courier" class=3D"">};</font></div><=
div class=3D""><font face=3D"Courier" class=3D""><br class=3D""></font></di=
v><div class=3D""><font face=3D"Courier" class=3D"">struct polymorphic {</f=
ont></div><div class=3D""><font face=3D"Courier" class=3D""> v=
irtual ~ </font><span style=3D"font-family: Courier;" class=3D"">polym=
orphic</span><font face=3D"Courier" class=3D"">() =3D default;</font></div>=
<div class=3D""><font face=3D"Courier" class=3D"">};</font></div><div class=
=3D""><br class=3D""></div><div class=3D"">Note, such classes should only b=
e used with private inheritance. As public bases they create potential dyna=
mic =E2=80=9Csibling=E2=80=9D casts, which bloats RTTI.</div></div><div cla=
ss=3D""><br class=3D""></div><div class=3D"">This covers most of the use-ca=
ses with equal terseness, but not <font face=3D"Courier" class=3D"">default=
default_ctor;</font>. I think that the default constructor belongs with th=
e rest of the constructors anyway.</div><div class=3D""><br class=3D""></di=
v><div class=3D"">(I=E2=80=99m not endorsing such usage, I=E2=80=99m just p=
ointing out the possibility.)</div></body></html>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
--Apple-Mail=_B39706FC-7C50-45F4-AB61-13FE2DB9BAB1--
.
Author: Benjamin Lindley <benjameslindley@gmail.com>
Date: Mon, 5 Jan 2015 07:04:03 -0800 (PST)
Raw View
------=_Part_5728_29242547.1420470243613
Content-Type: multipart/alternative;
boundary="----=_Part_5729_1853215913.1420470243613"
------=_Part_5729_1853215913.1420470243613
Content-Type: text/plain; charset=UTF-8
On Monday, January 5, 2015 2:26:06 AM UTC-6, Douglas Boffey wrote:
>
> Would default all generate a virtual dtor or non-virtual?
I would say non-virtual. Since that is what will be the case if you simply
type nothing.
> What about default assign for copy & move assignments?
>
I considered that. Enabling assignment specifically while not enabling
copy/move construction seems like a strange thing to do. Are there use
cases for that? Well, if that's something people would find useful, it can
certainly be added to the list.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
------=_Part_5729_1853215913.1420470243613
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Monday, January 5, 2015 2:26:06 AM UTC-6, Dougl=
as Boffey wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Would default =
all generate a virtual dtor or non-virtual?</blockquote><div><br>I would sa=
y non-virtual. Since that is what will be the case if you simply type nothi=
ng.<br> </div><blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"> What=
about
default assign for copy & move assignments?
<br></blockquote><div><br>I considered that. Enabling assignment specifical=
ly while not enabling copy/move construction seems like a strange thing to =
do. Are there use cases for that? Well, if that's something people would fi=
nd useful, it can certainly be added to the list.<br></div></div>
<p></p>
-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_5729_1853215913.1420470243613--
------=_Part_5728_29242547.1420470243613--
.
Author: Matthew Woehlke <mw_triad@users.sourceforge.net>
Date: Mon, 05 Jan 2015 11:00:51 -0500
Raw View
On 2015-01-04 17:14, Benjamin Lindley wrote:
> I think most people would agree that being explicit about what code should
> or shouldn't be automatically generated is a good thing. However, this:
>
> Bar() = default;
> Bar(Bar const&) = default;
> Bar(Bar&&) = default;
> Bar& operator=(Bar const&) = default;
> Bar& operator=(Bar&&) = default;
> ~Bar() = default;
>
> is a lot of noise for something that is going to happen anyway if I simply
> type nothing. I suggest a shortcut syntax. First, for individual members:
>
> default default_ctor; // generate default constructor
> default copy_ctor; // generate copy constructor
> default move_ctor; // generate move constructor
> default copy_assign; // generate copy assignment operator
> default move_assign; // generate move assignment operator
> default dtor; // generate destructor
> default virtual_dtor; // generate virtual destructor
#define DEFAULT_COPY_AND_MOVE(Bar) \
Bar(Bar const&) = default; \
Bar(Bar&&) = default;
....and yes I have done this in real code. See also e.g. Q_DISABLE_COPY
for a similar example in widespread use.
--
Matthew
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.
.