220 13941 <27e2ae9c-8b1f-4688-9bb3-9caef6bf4f54@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 15:22:53 -0700 (PDT)
Lines: 174
Approved: news@gmane.org
Message-ID: <27e2ae9c-8b1f-4688-9bb3-9caef6bf4f54@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>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_5730_1346458005.1413411773510"
X-Trace: ger.gmane.org 1413411783 27383 80.91.229.3 (15 Oct 2014 22:23:03 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 15 Oct 2014 22:23:03 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDKLT4PURQHRBPXH7OQQKGQEU6MANCY@isocpp.org Thu Oct 16 00:22:57 2014
Return-path: <std-proposals+bncBDKLT4PURQHRBPXH7OQQKGQEU6MANCY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ie0-f197.google.com ([209.85.223.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDKLT4PURQHRBPXH7OQQKGQEU6MANCY@isocpp.org>)
	id 1XeWy8-0005np-93
	for gclcip-std-proposals@m.gmane.org; Thu, 16 Oct 2014 00:22:56 +0200
Original-Received: by mail-ie0-f197.google.com with SMTP id rp18sf8940831iec.0
        for <gclcip-std-proposals@m.gmane.org>; Wed, 15 Oct 2014 15:22:55 -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=zVSn4HiVdWM/fayAxWxxfV3b5BYJe9n6LtPVG2kGqtU=;
        b=pDWU35fzUryvZZo+9UE5spc22FubWwW1ey+H6Dw5oc/rTfeecARVFFBf32TMlbbeLh
         7cgTRXzQ671WUqPtFKX7TjS7Y1SIS3GLIGZT+2ByLQCHq5kx6gQcZx21DnpgIw+6PEJu
         wOLt45BRVKIneatVHn3+UAC/Yj3fzfs5i/Oq4a/ixRF4cOXMoP3HvKNsY/IXYSCTABYb
         sVYccaSwTfMO4vb0Mk+5uYapPgFQnc8OH9HDc/DoEdrtaaJUhb3f6rbJVbiTduiGYoCw
         iecyVV+XzGqCMbZfmCgXIusvytf4K23/WKSjSRh/C75ePmNAfI0qn1ymnnvybyk5eRmA
         t4TQ==
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=zVSn4HiVdWM/fayAxWxxfV3b5BYJe9n6LtPVG2kGqtU=;
        b=McSH6UdYhKJ5fgCrIQR9wnpRlSfzwfkOzYlr/dVTZd3mVRlTEYhY6iW3LIEny8QdOH
         2PivK9MEFIIfEcDtUsz2boPQoz5wbrMF19gJ4UNt3SE7hKdNNrggFKnV9KGr0qpjNlT6
         ecrL2jNSsjkI713lQwk8589gQItpFu5NViiEBTEXQszxr4qC3YZH6xAKvmz9LcEAzeOt
         CfDZQ/HsNb7VCBIgiywgSwClKWcnKnWbid2lJFbFbobcVIRcucNWc5/8D4EXmZCCl/r0
         nHPYWqg9V+ZQo2ca4N679OuPm2aBRTzOtG7IHKkOh8J8obTiGvjwT245WHeGeUidm8DV
         IVaA==
X-Gm-Message-State: ALoCoQlFSnWF/Xa55JvviobeUg75exYmVt2F2QgTHZ4Z4K0jiL6u9IIiEOj/V7UDnr8LleQ34qmx
X-Received: by 10.50.51.34 with SMTP id h2mr615317igo.5.1413411775365;
        Wed, 15 Oct 2014 15:22:55 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.161.212 with SMTP id k203ls382221ioe.24.gmail; Wed, 15 Oct
 2014 15:22:54 -0700 (PDT)
X-Received: by 10.50.20.198 with SMTP id p6mr263210ige.10.1413411774866;
        Wed, 15 Oct 2014 15:22:54 -0700 (PDT)
In-Reply-To: <CAFk2RUZ7w3jpuJU1Hqr2=qfDJQycG0P8az+QwsWCG8mBQWi8Jg@mail.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:13941
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/13941>

------=_Part_5730_1346458005.1413411773510
Content-Type: text/plain; charset=UTF-8

On Wednesday, October 15, 2014 3:02:28 PM UTC-7, Ville Voutilainen wrote:
>
> On 16 October 2014 00:17, Myriachan <myri...@gmail.com <javascript:>> 
> wrote: 
> >> It's called std::experimental::optional. 
> > While that is a nice feature, it's not the same as needing to do this to 
> > types that weren't created as std::optional<T>. 
>
>
> Some questions: 
>
> 1) if you can refactor code to take into use this reconstruction 
> function, do you 
> think you can't change the same code to start using optional? If so, why? 
>
>
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.


2) do you think this function is important and common enough to standardize 
> it, 
> and if so, based on what(*)? 
>
> (*) I'm looking for more than anecdotes here, because if you say "I use 
> such 
> a thing every day", I will respond "whereas I never use such things, 
> so let's call 
> it a push". ;) 
>

After thinking more deeply about the exception implications, prompted by 
Nevin's reply, I can see how this is quite dangerous, since there's no way 
to stop a local destructor from executing.  I just saw it as shorthand for 
what people do already. 

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_5730_1346458005.1413411773510
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Wednesday, October 15, 2014 3:02:28 PM UTC-7, Ville Vou=
tilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On 16 October 2=
014 00:17, Myriachan &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfu=
scated-mailto=3D"fbazzRHkyrUJ" onmousedown=3D"this.href=3D'javascript:';ret=
urn true;" onclick=3D"this.href=3D'javascript:';return true;">myri...@gmail=
..com</a>&gt; wrote:
<br>&gt;&gt; It's called std::experimental::optional.
<br>&gt; While that is a nice feature, it's not the same as needing to do t=
his to
<br>&gt; types that weren't created as std::optional&lt;T&gt;.
<br>
<br>
<br>Some questions:
<br>
<br>1) if you can refactor code to take into use this reconstruction
<br>function, do you
<br>think you can't change the same code to start using optional? If so, wh=
y?
<br>
<br></blockquote><div><br>The main reason to use something like this is for=
 copy constructors.&nbsp; Sometimes, the most convenient way to implement a=
 copy or move constructor is like this:<br><br><div class=3D"prettyprint" s=
tyle=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 1=
87); 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-prettify">T </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">::</span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">operator</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D(=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> T </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">copy</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">if</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">(&amp;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">copy </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
!=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">this</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nb=
sp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">this</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;~</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; &nbsp; &nbsp; =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">new</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">this</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">copy</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>&nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">*</=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">this</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br></span></div></code></div><br>...and e=
quivalently with std::forward for move constructors.<br><br><br></div><bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;">2) do you think this function is im=
portant and common enough to standardize it,
<br>and if so, based on what(*)?
<br>
<br>(*) I'm looking for more than anecdotes here, because if you say "I use=
 such
<br>a thing every day", I will respond "whereas I never use such things,
<br>so let's call
<br>it a push". ;)
<br></blockquote><div><br>After thinking more deeply about the exception im=
plications, prompted by Nevin's reply, I can see how this is quite dangerou=
s, since there's no way to stop a local destructor from executing.&nbsp; I =
just saw it as shorthand for what people do already. <br><br>Melissa<br></d=
iv></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_5730_1346458005.1413411773510--

.
