220 4771 <CAFk2RUaSNATNAAvFi-RE58QgT82h=r_Vfgkq28XS_-Xjgcn+JA@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Ville Voutilainen <ville.voutilainen@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Implementability of std::optional
Date: Fri, 31 May 2013 18:47:22 +0300
Lines: 118
Approved: news@gmane.org
Message-ID: <CAFk2RUaSNATNAAvFi-RE58QgT82h=r_Vfgkq28XS_-Xjgcn+JA@mail.gmail.com>
References: <c28d0be7-5dea-462a-915c-3da36519cafa@isocpp.org>
	<dce0cd93-232c-4932-87e2-df99303a951a@isocpp.org>
	<00ac95c4-9e88-40eb-9564-41d8ed4d84ee@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=047d7bdca64ae290cc04de058755
X-Trace: ger.gmane.org 1370015246 27519 80.91.229.3 (31 May 2013 15:47:26 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 31 May 2013 15:47:26 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC5JHI7A7ALRBC4MUOGQKGQEVYXSHYA@isocpp.org Fri May 31 17:47:26 2013
Return-path: <std-proposals+bncBC5JHI7A7ALRBC4MUOGQKGQEVYXSHYA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qe0-f70.google.com ([209.85.128.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC5JHI7A7ALRBC4MUOGQKGQEVYXSHYA@isocpp.org>)
	id 1UiRY5-0007Sx-3G
	for gclcip-std-proposals@m.gmane.org; Fri, 31 May 2013 17:47:25 +0200
Original-Received: by mail-qe0-f70.google.com with SMTP id 2sf2182364qea.9
        for <gclcip-std-proposals@m.gmane.org>; Fri, 31 May 2013 08:47:24 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-beenthere:mime-version:in-reply-to:references:date:message-id
         :subject:from:to:x-original-sender:x-original-authentication-results
         :reply-to:precedence:mailing-list:list-id:x-google-group-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=MpaksuHWcI5s2sPzb0wrhzUGo8MAKG+aPTwXkh1ke2Q=;
        b=OV/9uuTHDbRZ9fQ/nZj79Ukn+KGiL7DEkp5IGMy6YYXm+4sUQHv3x8VWeMX6ilQbze
         5D/5KozBi3cw361witEvA8VBpHm6Ex/A5bEsNXhYhRJJLrW671sOMWiXSCfRBmPU/AIn
         sU7T0z41QG8ks5dLJEHHvLoPPUdbJppz/3dduzpAs8c4XHGMS09DristwhuceDzLmDZA
         Qe7y4h81Ut7O7qit2w12eWv8PsND9VPsTRnFY+6ZmAonoZh66CRDg+SD65Z7LDJnY+bj
         shmPSh05lr31+MkxADUXfEg030hNvu2XnW9pIOvADbbuJxY+YLi3SoCX+GCWYt3SBJPR
         p0pQ==
X-Received: by 10.224.174.145 with SMTP id t17mr6941387qaz.4.1370015243984;
        Fri, 31 May 2013 08:47:23 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.4.1 with SMTP id g1ls955554qeg.64.gmail; Fri, 31 May 2013
 08:47:22 -0700 (PDT)
X-Received: by 10.224.7.195 with SMTP id e3mr10011664qae.5.1370015242952;
        Fri, 31 May 2013 08:47:22 -0700 (PDT)
Original-Received: from mail-qe0-f46.google.com (mail-qe0-f46.google.com [209.85.128.46])
        by mx.google.com with ESMTPS id c10si36395664qam.59.2013.05.31.08.47.22
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 31 May 2013 08:47:22 -0700 (PDT)
Received-SPF: pass (google.com: domain of ville.voutilainen@gmail.com designates 209.85.128.46 as permitted sender) client-ip=209.85.128.46;
Original-Received: by mail-qe0-f46.google.com with SMTP id w7so190773qeb.5
        for <std-proposals@isocpp.org>; Fri, 31 May 2013 08:47:22 -0700 (PDT)
X-Received: by 10.224.71.211 with SMTP id i19mr10106814qaj.27.1370015242816;
 Fri, 31 May 2013 08:47:22 -0700 (PDT)
Original-Received: by 10.224.174.143 with HTTP; Fri, 31 May 2013 08:47:22 -0700 (PDT)
In-Reply-To: <00ac95c4-9e88-40eb-9564-41d8ed4d84ee@isocpp.org>
X-Original-Sender: ville.voutilainen@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of ville.voutilainen@gmail.com designates 209.85.128.46 as permitted
 sender) smtp.mail=ville.voutilainen@gmail.com;       dkim=pass header.i=@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?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:4771
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/4771>

--047d7bdca64ae290cc04de058755
Content-Type: text/plain; charset=ISO-8859-1

On 31 May 2013 18:17, Nikolay Ivchenkov <mk.ivchenkov@gmail.com> wrote:

> On Friday, May 31, 2013 5:42:45 PM UTC+4, DeadMG wrote:
>>
>> A trivial example not involving optional would be, say, the last element
>> of a std::vector. It's quite legal and normal for the user to overwrite
>> reference locations by destructing the original object and reconstructing a
>> new one in it's place.
>>
>
> We can do that:
>
>     #include <iostream>
>     #include <new>
>     #include <vector>
>
>     struct A
>     {
>
>         A(int &x) : ref(x) {}
>         int &ref;
>     };
>
>     int main()
>     {
>         std::vector<A> v;
>
>         int n1 = 0, n2 = 0;
>
>         v.emplace_back(n1);
>         A *p = &v.back();
>
>         p->~A();
>         A *q = new(p) A(n2);
>
>         q->ref = 1; // q->ref shall refer to n2
>         p->ref = 2; // p->ref may refer to n1
>
>         std::cout << n1 << " " << n2 << std::endl;
>     }
>
>
>
I suppose the vector internally has a pointer to the beginning of its
buffer, which is practically
a pointer to the first element, but since we reallocated a new element in
its place, the internal
pointer in the vector may or may not refer to the first element?

-- 

--- 
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/?hl=en.



--047d7bdca64ae290cc04de058755
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 31 May 2013 18:17, Nikolay Ivchenkov <span dir=3D"ltr">&lt;<a hr=
ef=3D"mailto:mk.ivchenkov@gmail.com" target=3D"_blank">mk.ivchenkov@gmail.c=
om</a>&gt;</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div class=3D"im">On Friday, May 31, 2013 5:=
42:45 PM UTC+4, DeadMG wrote:<blockquote class=3D"gmail_quote" style=3D"mar=
gin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>A trivial example not involving optional would be, say, the last eleme=
nt of a std::vector. It&#39;s quite legal and normal for the user to overwr=
ite reference locations by destructing the original object and reconstructi=
ng a new one in it&#39;s place.</div>
</blockquote></div><div><br>We can do that:<br><br><span style=3D"font-fami=
ly:courier new,monospace">=A0=A0=A0 #include &lt;iostream&gt;<br>=A0=A0=A0 =
#include &lt;new&gt;<br>=A0=A0=A0 #include &lt;vector&gt;<br><br>=A0=A0=A0 =
struct A<br>=A0=A0=A0 {<div class=3D"im">
<br>=A0=A0=A0=A0=A0=A0=A0 A(int &amp;x) : ref(x) {}<br>=A0=A0=A0=A0=A0=A0=
=A0 int &amp;ref;<br>=A0=A0=A0 };<br><br>=A0=A0=A0 int main()<br>=A0=A0=A0 =
{<br></div>=A0=A0=A0=A0=A0=A0=A0 std::vector&lt;A&gt; v;<div class=3D"im"><=
br>=A0=A0=A0=A0=A0=A0=A0 int n1 =3D 0, n2 =3D 0;<br><br></div>=A0=A0=A0=A0=
=A0=A0=A0 v.emplace_back(n1);<br>
=A0=A0=A0=A0=A0=A0=A0 A *p =3D &amp;v.back();<br><br>=A0=A0=A0=A0=A0=A0=A0 =
p-&gt;~A();<br>=A0=A0=A0=A0=A0=A0=A0 A *q =3D new(p) A(n2);<br><br>=A0=A0=
=A0=A0=A0=A0=A0 q-&gt;ref =3D 1; // q-&gt;ref shall refer to n2<br>=A0=A0=
=A0=A0=A0=A0=A0 p-&gt;ref =3D 2; // p-&gt;ref may refer to n1<div class=3D"=
im"><br>
=A0=A0=A0=A0=A0=A0=A0 std::cout &lt;&lt; n1 &lt;&lt; &quot; &quot; &lt;&lt;=
 n2 &lt;&lt; std::endl;<br>=A0=A0=A0 }</div></span><br><br></div></blockquo=
te><div><br></div><div>I suppose the vector internally has a pointer to the=
 beginning of its buffer, which is practically<br>
a pointer to the first element, but since we reallocated a new element in i=
ts place, the internal<br></div><div>pointer in the vector may or may not r=
efer to the first element? <br></div></div><br></div></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

--047d7bdca64ae290cc04de058755--

.
