220 13944 <97718d4b-0b69-40c1-b3e3-e0ab196d6f10@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Myriachan <myriachan@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Reconstruct function idea
Date: Wed, 15 Oct 2014 19:03:00 -0700 (PDT)
Lines: 150
Approved: news@gmane.org
Message-ID: <97718d4b-0b69-40c1-b3e3-e0ab196d6f10@isocpp.org>
References: <ff612334-ae16-43d1-a650-580d0ce635f2@isocpp.org> <CAGg_6+OH-P=uxCx7YEWdJSRtrRfBYhGXh55eymvyM9Vjr+yKMg@mail.gmail.com> <8a74f08b-7453-4d1a-9f20-bc1d3866617c@isocpp.org> <CAFk2RUZ7w3jpuJU1Hqr2=qfDJQycG0P8az+QwsWCG8mBQWi8Jg@mail.gmail.com> <27e2ae9c-8b1f-4688-9bb3-9caef6bf4f54@isocpp.org>
 <F4908FC0-1467-42DB-8B33-42326A986C92@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_123_1538419150.1413424980736"
X-Trace: ger.gmane.org 1413424996 7712 80.91.229.3 (16 Oct 2014 02:03:16 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 16 Oct 2014 02:03:16 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDKLT4PURQHRBVWO7SQQKGQEEETLDMQ@isocpp.org Thu Oct 16 04:03:04 2014
Return-path: <std-proposals+bncBDKLT4PURQHRBVWO7SQQKGQEEETLDMQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vc0-f198.google.com ([209.85.220.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDKLT4PURQHRBVWO7SQQKGQEEETLDMQ@isocpp.org>)
	id 1XeaPA-0008UU-6M
	for gclcip-std-proposals@m.gmane.org; Thu, 16 Oct 2014 04:03:04 +0200
Original-Received: by mail-vc0-f198.google.com with SMTP id hq12sf4991233vcb.5
        for <gclcip-std-proposals@m.gmane.org>; Wed, 15 Oct 2014 19:03:03 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=djGJnoBxLgVFqmAfDg3cWWAocS69OMyz79r+jw9aNOg=;
        b=S02B16avkgy5HoEV5smkBlB5l8oahsLiiz3s4QRqdKiD0YNKx0rLdjjjfu+YfEXSD7
         jVpdDJWXWGtFVa8XxSLVMusHOI1zhRb/gLYJlDZ+3AHgFkJDwyFLGtOszPpSCpzpjLBx
         ww3PiFOoy6dkoMu47QycxncroVICqrvJTPQIyKbUReqLKdkzhpyaYhpVRofSobSyEX90
         iAYrBIWmlyug8tL2Z8wj14dBikw3HV7Ps1w8s6d41AK8hg50Gw6fEyDYnjbFzWL0hZJu
         E1mHa3qVIS8HmAIiIVh9ENKkRFo5GEn3Pvnkeo58YbU+fHHhbDB/hI43l2dqb2DDLHVS
         I7mw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=djGJnoBxLgVFqmAfDg3cWWAocS69OMyz79r+jw9aNOg=;
        b=Bo9sDqYmy5wb3pOaCnAaiJ8hnEwprFklF0+oAA7q5ycTAtsS3hZ7xaUP67e8+m4Fp8
         oC7TjIwA7zAcnQQU1R/uj1XRwCmxdXh1uXjSAO/87sBTgGDF5x7T91LIld2lhX0BVjGp
         dYwI6U+XBCp13qV08sy770nRGatVQGrGmvRnIXvEY+pkZKmpeTp9jrkQVSfurLW0oiD4
         lVFUq6Gk1w5jbMiG1zFcwkS65op9WAg3S4HywXrTYxFAbLzyKvIrpiHjnCaX6k6lDWOd
         nk3z/lraztuBQTljc1x2BGaM0ol3JTANiR8wGtP9R0ahjfOrx86djoPhmEPuE5jOrgkP
         cXiw==
X-Gm-Message-State: ALoCoQnQZHJT3YDRy2W/EEQ5yZaUksJhs+Lk4KZI0iMJfQgvF7ITG1Fz0gFbxPAQLoe9HFFdQ2xe
X-Received: by 10.236.198.165 with SMTP id v25mr11392242yhn.51.1413424983251;
        Wed, 15 Oct 2014 19:03:03 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.107.72 with SMTP id ha8ls450203igb.10.gmail; Wed, 15 Oct
 2014 19:03:02 -0700 (PDT)
X-Received: by 10.50.134.69 with SMTP id pi5mr271019igb.2.1413424982510;
        Wed, 15 Oct 2014 19:03:02 -0700 (PDT)
In-Reply-To: <F4908FC0-1467-42DB-8B33-42326A986C92@gmail.com>
X-Original-Sender: myriachan@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:13944
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/13944>

------=_Part_123_1538419150.1413424980736
Content-Type: text/plain; charset=UTF-8

On Wednesday, October 15, 2014 3:31:39 PM UTC-7, Miro Knejp wrote:
>
> On 16 Oct 2014, at 00:22 , Myriachan <myri...@gmail.com <javascript:>> 
> wrote:
>
> The main reason to use something like this is for copy constructors.  
> Sometimes, the most convenient way to implement a copy or move constructor 
> is like this:
>
> T &T::operator =(const T &copy)
> {
>     if (&copy != this)
>     {
>         this->~T();
>         new(this) T(copy);
>     }
>     return *this;
> }
>
> ...and equivalently with std::forward for move constructors.
>
>
> This would never pass my code review. If that constructor throws you're 
> doomed. Use copy-and-swap instead, it provides strong exception guarantee 
> and won't leave you with a destroyed object. Move constructors are a 
> different game though and the compiler-defaulted one should do it's job 
> just fine in most cases.
>
> T& T::operator =(const T& copy)
> {
>     if (&copy != this)
>     {
>         T x{copy};
>         swap(*this, x);
>     }
>     return *this;
> }
>
>
I suppose the difference is that I work on a project that disables C++ 
exceptions because they're too slow.  swap would be slow or unusable if 
there's either no overload for it nor move constructors, which for a 
codebase of millions of lines written before C++11 is likely.

Enabling C++ exception handling is a massive performance decrease in x86-32 
Windows.  If it's enabled in the compiler, even if no exceptions are used, 
every function with an automatic variable whose type has a destructor will 
be ~20 instructions longer due to setting up the exception frame.

Melissa

-- 

--- 
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_123_1538419150.1413424980736
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, October 15, 2014 3:31:39 PM UTC-7, Miro Knej=
p wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wra=
p:break-word"><div><div>On 16 Oct 2014, at 00:22 , Myriachan &lt;<a href=3D=
"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"c9vIXik38_QJ" onmo=
usedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'=
javascript:';return true;">myri...@gmail.com</a>&gt; wrote:</div><blockquot=
e type=3D"cite"><div dir=3D"ltr">The main reason to use something like this=
 is for copy constructors.&nbsp; Sometimes, the most convenient way to impl=
ement a copy or move constructor is like this:<br><div><br><div style=3D"ba=
ckground-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap=
:break-word"><code>T <span style=3D"color:#660">&amp;</span>T<span style=3D=
"color:#660">::</span><span style=3D"color:#008">operator</span> <span styl=
e=3D"color:#660">=3D(</span><span style=3D"color:#008">const</span> T <span=
 style=3D"color:#660">&amp;</span>copy<span style=3D"color:#660">)</span><b=
r><span style=3D"color:#660">{</span><br>&nbsp; &nbsp; <span style=3D"color=
:#008">if</span> <span style=3D"color:#660">(&amp;</span>copy <span style=
=3D"color:#660">!=3D</span> <span style=3D"color:#008">this</span><span sty=
le=3D"color:#660">)</span><br>&nbsp; &nbsp; <span style=3D"color:#660">{</s=
pan><br>&nbsp; &nbsp; &nbsp; &nbsp; <span style=3D"color:#008">this</span><=
span style=3D"color:#660">-&gt;~</span>T<span style=3D"color:#660">();</spa=
n><br>&nbsp; &nbsp; &nbsp; &nbsp; <span style=3D"color:#008">new</span><spa=
n style=3D"color:#660">(</span><span style=3D"color:#008">this</span><span =
style=3D"color:#660">)</span> T<span style=3D"color:#660">(</span>copy<span=
 style=3D"color:#660">);</span><br>&nbsp; &nbsp; <span style=3D"color:#660"=
>}</span><br>&nbsp; &nbsp; <span style=3D"color:#008">return</span> <span s=
tyle=3D"color:#660">*</span><span style=3D"color:#008">this</span><span sty=
le=3D"color:#660">;</span><br><span style=3D"color:#660">}</span><br></code=
></div><br>...and equivalently with std::forward for move constructors.<br>=
</div></div></blockquote><div><br></div>This would never pass my code revie=
w. If that constructor throws you're doomed. Use copy-and-swap instead, it =
provides strong exception guarantee and won't leave you with a destroyed ob=
ject. Move constructors are a different game though and the compiler-defaul=
ted one should do it's job just fine in most cases.</div><div><br></div><di=
v><div dir=3D"ltr"><div style=3D"background-color:rgb(250,250,250);border:1=
px solid rgb(187,187,187);word-wrap:break-word"><code>T<span style=3D"color=
:rgb(102,102,0)">&amp;&nbsp;</span>T<span style=3D"color:rgb(102,102,0)">::=
</span><span style=3D"color:rgb(0,0,136)">operator</span>&nbsp;<span style=
=3D"color:rgb(102,102,0)">=3D(</span><span style=3D"color:rgb(0,0,136)">con=
st</span>&nbsp;T<span style=3D"color:rgb(102,102,0)">&amp;&nbsp;</span>copy=
<span style=3D"color:rgb(102,102,0)"><wbr>)</span><br><span style=3D"color:=
rgb(102,102,0)">{</span><br>&nbsp; &nbsp;&nbsp;<span style=3D"color:rgb(0,0=
,136)">if</span>&nbsp;<span style=3D"color:rgb(102,102,0)">(&amp;</span>cop=
y&nbsp;<span style=3D"color:rgb(102,102,0)">!=3D</span>&nbsp;<span style=3D=
"color:rgb(0,0,136)">this</span><span style=3D"color:rgb(102,102,0)">)</spa=
n><br>&nbsp; &nbsp;&nbsp;<span style=3D"color:rgb(102,102,0)">{</span><br>&=
nbsp; &nbsp; &nbsp; &nbsp;&nbsp;T x<span style=3D"color:rgb(102,102,0)">{co=
py};</span><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style=3D"color:rgb(0,=
0,136)">swap</span><span style=3D"color:rgb(102,102,0)">(*</span><span styl=
e=3D"color:rgb(0,0,136)">this</span><span><font color=3D"#666600">,&nbsp;</=
font></span>x<span style=3D"color:rgb(102,102,0)">);</span><br>&nbsp; &nbsp=
;&nbsp;<span style=3D"color:rgb(102,102,0)">}</span><br>&nbsp; &nbsp;&nbsp;=
<span style=3D"color:rgb(0,0,136)">return</span>&nbsp;<span style=3D"color:=
rgb(102,102,0)">*</span><span style=3D"color:rgb(0,0,136)">this</span><span=
 style=3D"color:rgb(102,102,0)">;</span><br><span style=3D"color:rgb(102,10=
2,0)">}</span><br></code></div></div><div></div></div><br></div></blockquot=
e><div><br>I suppose the difference is that I work on a project that disabl=
es C++ exceptions because they're too slow.&nbsp; swap would be slow or unu=
sable if there's either no overload for it nor move constructors, which for=
 a codebase of millions of lines written before C++11 is likely.<br><br>Ena=
bling C++ exception handling is a massive performance decrease in x86-32 Wi=
ndows.&nbsp; If it's enabled in the compiler, even if no exceptions are use=
d, every function with an automatic variable whose type has a destructor wi=
ll be ~20 instructions longer due to setting up the exception frame.<br><br=
>Melissa<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&quot; 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_123_1538419150.1413424980736--

.
