220 28976 <cb8b588b-c265-416c-9b82-c074e28235d9@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Evan Teran <evan.teran@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: A means to access the encapsulating object within
 a member
Date: Wed, 19 Oct 2016 08:02:07 -0700 (PDT)
Lines: 120
Approved: news@gmane.org
Message-ID: <cb8b588b-c265-416c-9b82-c074e28235d9@isocpp.org>
References: <4dffbd31-0ae3-4a10-9b57-f50f7e6aa8e7@isocpp.org>
 <c3476dd7-7b32-4135-b4f3-fbafae3608c1@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_217_1514164744.1476889327493"
X-Trace: blaine.gmane.org 1476889351 31824 195.159.176.226 (19 Oct 2016 15:02:31 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 19 Oct 2016 15:02:31 +0000 (UTC)
Cc: mihailnajdenov@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCDNZQVEQMLRB4MVT3AAKGQEL53XFCY@isocpp.org Wed Oct 19 17:02:23 2016
Return-path: <std-proposals+bncBCDNZQVEQMLRB4MVT3AAKGQEL53XFCY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb0-f200.google.com ([209.85.213.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCDNZQVEQMLRB4MVT3AAKGQEL53XFCY@isocpp.org>)
	id 1bwsNd-0005wU-V0
	for gclcip-std-proposals@m.gmane.org; Wed, 19 Oct 2016 17:02:10 +0200
Original-Received: by mail-yb0-f200.google.com with SMTP id 206sf26317659ybp.4
        for <gclcip-std-proposals@m.gmane.org>; Wed, 19 Oct 2016 08:02:12 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=LdxTjafwCNT5ncUMJilWudqSxXi+tcbJ7snnm4a8JQg=;
        b=IwQu+w78NWlWY1QThavqJWnA4pp3VNl5pvcAVGCpIFxFxe8oOTmEzZ/FK13I8sV25h
         LNOODF9jtKhcVfiizHXOwVj2vubu+ew9kzz2yZfrpMSHY3v7xjfeVr/XX4cFNI4KqBPA
         umiQG5+BOhU6JT1vcGNK4+yTskoXmTxnbEH3SLkxVWyoX1XObvi+lkZ0OeNEL5quNTaC
         +p6kpbFKC969hP3i0Tlj86ZQy7KIJT2MSlWa+c/IecQ8Nn0nio/9BrC0x6ZR3QBIFrd4
         3cM5/fuB1mh4JVir5u1lgC/3YCjpS3hN3hNARcegY/HX/tegOOOFsp6g6tjAjCWngdP2
         31Yg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=LdxTjafwCNT5ncUMJilWudqSxXi+tcbJ7snnm4a8JQg=;
        b=pa2u6dpfOCJz2wBuNO11Ww4DfTyVjgmFg9rhoqJmZlhh7Mn8iKNMw+oWgGe5Rulb0K
         6CaD02KIdNwDFODR61WnkH9oIGLTZdAb+W/XBaBVBT4nFi9GJJ8T+VX6qScK2Kx1lktr
         2L3p9S2zgT+haw3+WawB5RXT9MeL4iQbv6J0YgWFA4Q0Ywfh7AcvLi8RarZi01JsHB09
         ag7PMy9TcG9DtwSBEo68CbqLprRfA1ixep/sAq4ZPbD5bCq00Y3HF5U7aaikUU2W/9hc
         n5UNOIDm7xS5708J+X9s/lbXH4ZuWGlOQlctNS2BzRxIX0xmtz96QElQLhHVZDBbxdxl
         60Ng==
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:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=LdxTjafwCNT5ncUMJilWudqSxXi+tcbJ7snnm4a8JQg=;
        b=W9KzWEBV3jqBJ97CLwk4GTVFLHpR4KRLa6fqiJsvnQySqaGZic6r5JVkjiCC5dAiFz
         pKClBK+WLK9qwZ11YiVtXF4q6+x+4t/PEkrnlUuLqCQRvio3WKlHciHdp0gAKD5L+yKD
         Frh7t3tH40Mbzu/MOZNSi5rkDyJajtJgTIr3AYsQNsNc68XfU9FF568gtrPX2NC16GdL
         RMHj/18FDrPZdg2pmLneWTtGzuBEFNNCP/ZXvLNg5044dkyrd3EDlvw90XRMXDQfFinV
         qYcszOJUsS3mIanQuEUzbZk/5HTFClMW3ad/bLHpyl0thVVSPNjahUKU19K9zlnAUboN
         K1Dw==
X-Gm-Message-State: AA6/9RkdjRygsMWF0gFd/uvoqWWQx9XymVOFt2fbDedBfRoFiukgzRIgFOEvkplLQThvRw==
X-Received: by 10.129.117.70 with SMTP id q67mr2057249ywc.45.1476889332054;
        Wed, 19 Oct 2016 08:02:12 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.11.69 with SMTP id v66ls733270ioi.37.gmail; Wed, 19 Oct
 2016 08:02:09 -0700 (PDT)
X-Received: by 10.36.124.22 with SMTP id a22mr638364itd.4.1476889329244;
        Wed, 19 Oct 2016 08:02:09 -0700 (PDT)
In-Reply-To: <c3476dd7-7b32-4135-b4f3-fbafae3608c1@isocpp.org>
X-Original-Sender: evan.teran@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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:28976
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/28976>

------=_Part_217_1514164744.1476889327493
Content-Type: multipart/alternative; 
	boundary="----=_Part_218_749706940.1476889327493"

------=_Part_218_749706940.1476889327493
Content-Type: text/plain; charset=UTF-8

yes, you can store it via a constructor explicitly, I hadn't thought about 
using the in class version of the constructor which is nice.

On Wednesday, October 19, 2016 at 5:44:00 AM UTC-4, mihailn...@gmail.com 
wrote:
>
> But you can always store a pointer in the contained class to the 
> containing class
>
> template <class T, class Obj, T (Obj::*G)() const, void (Obj::*S)(T)>
> struct Property  
> {
>     Obj& operator=(const T &value) {
>         auto p = _that;
>         (p->*S)(value);
>         return *p; // we return the encapsulating object for intuitive 
> chaining
>     }
>     
>     operator T () const {
>         auto p = _that;
>         return (p->*G)();
>     }
>     
>     Obj* _that;
> };
>
>
> struct A {
>
> public:
>     int getMember() const { return member_; } // imagine that these are 
> complex routines
>     void setMember(int v) { member_ = v; }    // and we couldn't get the 
> same behavior by making member_ public
>
> public:
>     Property<int, A, &A::getMember, &A::setMember> member{this};
>     
> private:
>     int member_;
> };
>
>
> This compiles and runs today.
>
>

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/cb8b588b-c265-416c-9b82-c074e28235d9%40isocpp.org.

------=_Part_218_749706940.1476889327493
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">yes, you can store it via a constructor explicitly, I hadn=
&#39;t thought about using the in class version of the constructor which is=
 nice.<br><br>On Wednesday, October 19, 2016 at 5:44:00 AM UTC-4, mihailn..=
..@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr"><div>But you can always store a pointer in the contained class to the =
containing class</div><div><br></div><div style=3D"border:1px solid rgb(187=
,187,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><di=
v><span style=3D"color:#606"><font color=3D"rgb(34,34,34)" face=3D"Arial" s=
tyle=3D"background-color:transparent">template &lt;class T, class Obj, T (O=
bj::*G)() const, void (Obj::*S)(T)&gt;<br>struct Property=C2=A0 <br>{<br>=
=C2=A0=C2=A0=C2=A0 Obj&amp; operator=3D(const T &amp;value) {<br>=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 auto p =3D _that;<br>=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0 (p-&gt;*S)(value);<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0 return *p; // we return the encapsulating object for intuit=
ive chaining<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=
=C2=A0 operator T () const {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =
auto p =3D _that;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return (p-&=
gt;*G)();<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=A0=C2=A0 <br>=C2=A0=C2=A0=C2=
=A0 Obj* _that;<br>};</font></span></div><div><br></div><div><span style=3D=
"color:#606"><font color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"backgrou=
nd-color:transparent"><br>struct A {</font></span></div><div><br></div><div=
><span style=3D"color:#606"><font color=3D"rgb(34,34,34)" face=3D"Arial" st=
yle=3D"background-color:transparent">public:<br>=C2=A0=C2=A0=C2=A0 int getM=
ember() const { return member_; } // imagine that these are complex routine=
s<br>=C2=A0=C2=A0=C2=A0 void setMember(int v) { member_ =3D v; }=C2=A0=C2=
=A0=C2=A0 // and we couldn&#39;t get the same behavior by making member_ pu=
blic</font></span></div><div><br></div><div><span style=3D"color:#606"><fon=
t color=3D"rgb(34,34,34)" face=3D"Arial" style=3D"background-color:transpar=
ent">public:<br>=C2=A0=C2=A0=C2=A0 Property&lt;int, A, &amp;A::getMember, &=
amp;A::setMember&gt; member{this};<br>=C2=A0=C2=A0=C2=A0 <br>private:<br>=
=C2=A0=C2=A0=C2=A0 int member_;<br>};</font></span><span style=3D"color:#66=
0"></span></div></code></div><div><br></div><div><br></div><div>This compil=
es and runs today.</div><div><br></div></div></blockquote></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/cb8b588b-c265-416c-9b82-c074e28235d9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/cb8b588b-c265-416c-9b82-c074e28235d9=
%40isocpp.org</a>.<br />

------=_Part_218_749706940.1476889327493--

------=_Part_217_1514164744.1476889327493--

.
