220 40168 <9fd9c42a-916b-44de-8ab4-82d77df09859@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: "Ivan G." <nekotekina@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Class templates curiously parametrized by their own pointer-to-members
Date: Sun, 16 Sep 2018 15:01:47 -0700 (PDT)
Lines: 203
Approved: news@gmane.org
Message-ID: <9fd9c42a-916b-44de-8ab4-82d77df09859@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1411_1233671835.1537135307886"
X-Trace: blaine.gmane.org 1537135187 10100 195.159.176.226 (16 Sep 2018 21:59:47 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 16 Sep 2018 21:59:47 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD26JFH7QQHRBTFF7POAKGQEJCYVVAI@isocpp.org Sun Sep 16 23:59:43 2018
Return-path: <std-proposals+bncBD26JFH7QQHRBTFF7POAKGQEJCYVVAI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb1-f200.google.com ([209.85.219.200])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBD26JFH7QQHRBTFF7POAKGQEJCYVVAI@isocpp.org>)
	id 1g1f4u-0002UA-5l
	for gclcip-std-proposals@m.gmane.org; Sun, 16 Sep 2018 23:59:40 +0200
Original-Received: by mail-yb1-f200.google.com with SMTP id v12-v6sf9643903ybe.23
        for <gclcip-std-proposals@m.gmane.org>; Sun, 16 Sep 2018 15:01:51 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=eTqH4rvXMD5DD4zHcnPdHp9ut0rA2Vi3NIU9qm/Gr28=;
        b=QllVZy2nDuenTkpIw5Nyw6kcTf+yMhItZcSbSdf5I9YA10NRZe39Y/ut/heo5N2RZt
         sm/XoVrDLAswXYZlBRm6LGaDn7OEG+H1IQZ0gYxATJH6q5WS+S9KAnEnABTQVFsomjta
         Td/MofLJcSeWQi6KmVoZ7X8Zhl29d2yj30zdQKUwl8YJKz06Cc3t1hRhZmdrzcJt+89U
         /hkPNMS1JI17f4W+p/tQuZZYCTAjxpf2PfXnWXoo9qAIBGqmWnNrVnZygdTHJEbavsQ/
         WMV2aihRHt5DtRy1+CSHwESIjGUmzY1+/evK85WmEd7vyZ2/exHJPMGpaYILvlp+dXKr
         54Sg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=eTqH4rvXMD5DD4zHcnPdHp9ut0rA2Vi3NIU9qm/Gr28=;
        b=Tr5h68nuOz86xqZyEG5oEmWPJPrNpO+4RAtfQM2nsiknj3DsHyZgaEDuFXEQDS9cZH
         VUHAgiwgHK7c3YHCmIemHX5T9tcLn8MyDgCCOqfYheoJXb5wbG/Dl/IehRDE41Dt2bJO
         NKsvxOw0bap/PbksfB833nbiBKAavmITKGZA3lNcinybT0MnLb4dW4MVSl8AJtPA+5eP
         t6paL2YxY4EzIzVXaVZqeB8wqFV2YDDgJmcWk3wvwunslcxL+SjM8wnsW/ZV2Q9FNsr4
         12oCXPLoX0bWrNheMLq0+jDRl2aHPtM794n52kef3cO0malmKFXGSKI/UdkNSwxUKFaR
         IEFw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id: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=eTqH4rvXMD5DD4zHcnPdHp9ut0rA2Vi3NIU9qm/Gr28=;
        b=qVCQexF/SVlOK3T3L9bLcJiH71crJfkLepKo7L+ur9LKoM4yBx6Bh/d5Wpl00kQ7k8
         eVy6H71JpleIxaDBrDLisnYaMZ9rx45j+TBxT46Ck1oDEZJMBy+nAlO7V/xMgQTNgzy5
         BnZ4GKzQ/R1E0x/RxcF+O2XwAFjQZRLuE58vFLQQsPORJ89OAO/2q93gkcCY2B0KXDJb
         AhU0HLLQUu1W72ktfPrukUqULWs+ODfJvnGGsbLE0XvxcE2dpig3bdWal90ZDGZ9JuKq
         +K92OgP7VPzyepd9/OVd+yI4wq0b1pElN9rj8IKkqPSsPwnWs3OqKzCOTc20uUBFsJ51
         H3Qw==
X-Gm-Message-State: APzg51Cr7GitvJf9wQEKu0fuD3N1JOk1pcfJGkTp3Y3f+DLEnG5e3HkD
	T8IH2edal5iuqc4ZEOaCQ7woBA==
X-Google-Smtp-Source: ANB0Vda8IylhOun5KFvo2WvrWUoMkP/UVc2aOg9EH5h18esAQqGS1ehPhKVmosjmQ/4k4V8a7j3fyw==
X-Received: by 2002:a0d:e3c4:: with SMTP id m187-v6mr3540215ywe.50.1537135310282;
        Sun, 16 Sep 2018 15:01:50 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a25:ef4b:: with SMTP id w11-v6ls2869917ybm.16.gmail; Sun, 16
 Sep 2018 15:01:48 -0700 (PDT)
X-Received: by 2002:a25:c048:: with SMTP id c69-v6mr157838ybf.4.1537135308676;
        Sun, 16 Sep 2018 15:01:48 -0700 (PDT)
X-Original-Sender: nekotekina@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: 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:40168
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/40168>

------=_Part_1411_1233671835.1537135307886
Content-Type: multipart/alternative; 
	boundary="----=_Part_1412_119249185.1537135307886"

------=_Part_1412_119249185.1537135307886
Content-Type: text/plain; charset="UTF-8"

Hello, this is another simple attempt on properties, mixins, and adjacent 
problems. It probably doesn't contain anything new, maybe just another 
point of view.

The idea is to have special template parameter with special syntax, of 
pointer-to-member type, which turns the class template into a special one 
which cannot be instantiated outside of the context of another class. It 
can strictly become only a class member.


template <auto Prop, auto this::* This>
struct deeper
{
   int foo()
   {
       return z; // Ok: z belongs to property
   }

    int bar()
   {
       return static_cast<struct bar*>(this)->y.fu(); // Ok: can reach 
higher levels by casting pointer
   }
};

template <auto this::* This>
struct property
{
   int z;

    deeper<This> w;

    int fu()
   {
       // return this->z; // Error: bar doesn't have z

        return (this->*This).z; // Ok: 'this' points to bar
   }
};

struct bar
{
    property<> x; // 'This' is equal to &bar::x
    property<> y; // 'This' is equal to &bar::y

    // deeper<> inside the property should have zero side, just like empty 
base optimization
    static_assert(sizeof(x) == sizeof(int));
};


auto this::* is "magical" pointer-to-member, which is normally impossible 
and seems absurd at the first glance. However, I believe it's just a minor 
technical issue and can be implemented.

Because every member's type is unique, I believe that pointers to such 
members can be simply upcasted with static_cast.

Objects of such types obviously cannot be constructed.
Outer class is directly visible from inside of them, but I cannot decide to 
what extent, and how it should interact with inner classes' own members.

-- 
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/9fd9c42a-916b-44de-8ab4-82d77df09859%40isocpp.org.

------=_Part_1412_119249185.1537135307886
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello, this is another simple attempt on properties, mixin=
s, and adjacent problems. It probably doesn&#39;t contain anything new, may=
be just another point of view.<div><br></div><div>The idea is to have speci=
al template parameter with special syntax, of pointer-to-member type, which=
 turns the class template into a special one which cannot be instantiated o=
utside of the context of another class. It can strictly become only a class=
 member.<br></div><div><br></div><div><br><div style=3D"color: #000000;back=
ground-color: #ffffff;font-family: &#39;Droid Sans Mono&#39;, &#39;monospac=
e&#39;, monospace, &#39;Droid Sans Fallback&#39;;font-weight: normal;font-s=
ize: 14px;line-height: 19px;white-space: pre;"><div><span style=3D"color: #=
0000ff;">template </span><span style=3D"color: #000000;">&lt;</span><span s=
tyle=3D"color: #0000ff;">auto</span><span style=3D"color: #000000;"> Prop, =
</span><span style=3D"color: #0000ff;">auto</span><span style=3D"color: #00=
0000;"> </span><span style=3D"color: #0000ff;">this</span><span style=3D"co=
lor: #000000;">::</span><span style=3D"color: #000000;">*</span><span style=
=3D"color: #000000;"> This</span><span style=3D"color: #000000;">&gt;</span=
></div><div><span style=3D"color: #0000ff;">struct</span><span style=3D"col=
or: #000000;"> </span><span style=3D"color: #267f99;">deeper</span></div><d=
iv><span style=3D"color: #000000;">{</span></div><div><span style=3D"color:=
 #000000;"> =C2=A0 =C2=A0</span><span style=3D"color: #0000ff;">int</span><=
span style=3D"color: #000000;"> </span><span style=3D"color: #795e26;">foo<=
/span><span style=3D"color: #000000;">()</span></div><div><span style=3D"co=
lor: #000000;"> =C2=A0 =C2=A0{</span></div><div><span style=3D"color: #0000=
00;"> =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #af00db;">ret=
urn</span><span style=3D"color: #000000;"> z; </span><span style=3D"color: =
#008000;">// Ok: z belongs to property</span></div><div><span style=3D"colo=
r: #000000;"> =C2=A0 =C2=A0}</span></div><br><div><span style=3D"color: #00=
0000;">=C2=A0 =C2=A0 </span><span style=3D"color: #0000ff;">int</span><span=
 style=3D"color: #000000;"> </span><span style=3D"color: #795e26;">bar</spa=
n><span style=3D"color: #000000;">()</span></div><div><span style=3D"color:=
 #000000;"> =C2=A0 =C2=A0{</span></div><div><span style=3D"color: #000000;"=
> =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #af00db;">return<=
/span><span style=3D"color: #000000;"> </span><span style=3D"color: #0000ff=
;">static_cast</span><span style=3D"color: #000000;">&lt;</span><span style=
=3D"color: #0000ff;">struct</span><span style=3D"color: #000000;"> </span><=
span style=3D"color: #267f99;">bar</span><span style=3D"color: #000000;">*&=
gt;</span><span style=3D"color: #000000;">(</span><span style=3D"color: #00=
00ff;">this</span><span style=3D"color: #000000;">)-&gt;</span><span style=
=3D"color: #001080;">y</span><span style=3D"color: #000000;">.</span><span =
style=3D"color: #795e26;">fu</span><span style=3D"color: #000000;">(); </sp=
an><span style=3D"color: #008000;">// Ok: can reach higher levels by castin=
g pointer</span></div><div><span style=3D"color: #000000;"> =C2=A0 =C2=A0}<=
/span></div><div><span style=3D"color: #000000;">};</span></div><br><div><s=
pan style=3D"color: #0000ff;">template </span><span style=3D"color: #000000=
;">&lt;</span><span style=3D"color: #0000ff;">auto</span><span style=3D"col=
or: #000000;"> </span><span style=3D"color: #0000ff;">this</span><span styl=
e=3D"color: #000000;">::</span><span style=3D"color: #000000;">*</span><spa=
n style=3D"color: #000000;"> This</span><span style=3D"color: #000000;">&gt=
;</span></div><div><span style=3D"color: #0000ff;">struct</span><span style=
=3D"color: #000000;"> </span><span style=3D"color: #267f99;">property</span=
></div><div><span style=3D"color: #000000;">{</span></div><div><span style=
=3D"color: #000000;"> =C2=A0 =C2=A0</span><span style=3D"color: #0000ff;">i=
nt</span><span style=3D"color: #000000;"> z;</span></div><br><div><span sty=
le=3D"color: #000000;">=C2=A0 =C2=A0 deeper</span><span style=3D"color: #00=
0000;">&lt;</span><span style=3D"color: #000000;">This</span><span style=3D=
"color: #000000;">&gt;</span><span style=3D"color: #000000;"> w;<br></span>=
</div><br><div><span style=3D"color: #000000;">=C2=A0 =C2=A0 </span><span s=
tyle=3D"color: #0000ff;">int</span><span style=3D"color: #000000;"> </span>=
<span style=3D"color: #795e26;">fu</span><span style=3D"color: #000000;">()=
</span></div><div><span style=3D"color: #000000;"> =C2=A0 =C2=A0{</span></d=
iv><div><span style=3D"color: #000000;"> =C2=A0 =C2=A0 =C2=A0 =C2=A0</span>=
<span style=3D"color: #008000;">// return this-&gt;z; // Error: bar doesn&#=
39;t have z</span></div><br><div><span style=3D"color: #000000;">=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #af00db;">return</span><span=
 style=3D"color: #000000;"> (</span><span style=3D"color: #0000ff;">this</s=
pan><span style=3D"color: #000000;">-&gt;</span><span style=3D"color: #0000=
00;">*</span><span style=3D"color: #000000;">This).</span><span style=3D"co=
lor: #001080;">z</span><span style=3D"color: #000000;">; </span><span style=
=3D"color: #008000;">// Ok: &#39;this&#39; points to bar</span></div><div><=
span style=3D"color: #000000;"> =C2=A0 =C2=A0}</span></div><div><span style=
=3D"color: #000000;">};</span></div><br><div><div style=3D"color: #000000;b=
ackground-color: #ffffff;font-family: &#39;Droid Sans Mono&#39;, &#39;monos=
pace&#39;, monospace, &#39;Droid Sans Fallback&#39;;font-weight: normal;fon=
t-size: 14px;line-height: 19px;white-space: pre;"><div><span style=3D"color=
: #0000ff;">struct</span><span style=3D"color: #000000;"> </span><span styl=
e=3D"color: #267f99;">bar</span></div><div><span style=3D"color: #000000;">=
{</span></div><div><span style=3D"color: #000000;">=C2=A0=C2=A0=C2=A0=C2=A0=
property</span><span style=3D"color: #000000;">&lt;&gt;</span><span style=
=3D"color: #000000;"> x; </span><span style=3D"color: #008000;">// &#39;Thi=
s&#39; is equal to &amp;bar::x</span></div><div><span style=3D"color: #0000=
00;">=C2=A0=C2=A0=C2=A0=C2=A0property</span><span style=3D"color: #000000;"=
>&lt;&gt;</span><span style=3D"color: #000000;"> y; </span><span style=3D"c=
olor: #008000;">// &#39;This&#39; is equal to &amp;bar::y</span></div><br><=
div><span style=3D"color: #000000;">=C2=A0=C2=A0=C2=A0=C2=A0</span><span st=
yle=3D"color: #008000;">// deeper&lt;&gt; inside the property should have z=
ero side, just like empty base optimization</span></div><div><span style=3D=
"color: #000000;">=C2=A0=C2=A0=C2=A0=C2=A0</span><span style=3D"color: #795=
e26;">static_assert</span><span style=3D"color: #000000;">(</span><span sty=
le=3D"color: #0000ff;">sizeof</span><span style=3D"color: #000000;">(x) </s=
pan><span style=3D"color: #000000;">=3D=3D</span><span style=3D"color: #000=
000;"> </span><span style=3D"color: #0000ff;">sizeof</span><span style=3D"c=
olor: #000000;">(</span><span style=3D"color: #0000ff;">int</span><span sty=
le=3D"color: #000000;">));</span></div><div><span style=3D"color: #000000;"=
>};</span></div></div><span style=3D"color: #0000ff;"></span></div></div><b=
r><br>auto this::* is &quot;magical&quot; pointer-to-member, which is norma=
lly impossible and seems absurd at the first glance. However, I believe it&=
#39;s just a minor technical issue and can be implemented.</div><div><br></=
div><div>Because every member&#39;s type is unique, I believe that pointers=
 to such members can be simply upcasted with static_cast.</div><div><br></d=
iv><div>Objects of such types obviously cannot be constructed.</div><div>Ou=
ter class is directly visible from inside of them, but I cannot decide to w=
hat extent, and how it should interact with inner classes&#39; own members.=
</div></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/9fd9c42a-916b-44de-8ab4-82d77df09859%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9fd9c42a-916b-44de-8ab4-82d77df09859=
%40isocpp.org</a>.<br />

------=_Part_1412_119249185.1537135307886--

------=_Part_1411_1233671835.1537135307886--

.
