220 17127 <189212bb-bb9c-4c5d-a984-29ae41e32202@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Myriachan <myriachan@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: virtual constexpr fields
Date: Mon, 23 Mar 2015 14:30:33 -0700 (PDT)
Lines: 209
Approved: news@gmane.org
Message-ID: <189212bb-bb9c-4c5d-a984-29ae41e32202@isocpp.org>
References: <532355906.19321.1426710347371.JavaMail.yahoo@mail.yahoo.com> <04122f67-f4cd-457c-902e-589091f90063@isocpp.org>
 <2096343.oZu43OOe1O@tjmaciei-mobl4>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_5147_276563614.1427146233529"
X-Trace: ger.gmane.org 1427146242 21390 80.91.229.3 (23 Mar 2015 21:30:42 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 23 Mar 2015 21:30:42 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDKLT4PURQHRB6ULYKUAKGQE2O442QA@isocpp.org Mon Mar 23 22:30:37 2015
Return-path: <std-proposals+bncBDKLT4PURQHRB6ULYKUAKGQE2O442QA@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+bncBDKLT4PURQHRB6ULYKUAKGQE2O442QA@isocpp.org>)
	id 1Ya9vg-0007GV-Cn
	for gclcip-std-proposals@m.gmane.org; Mon, 23 Mar 2015 22:30:36 +0100
Original-Received: by iejg9 with SMTP id g9sf139748347iej.0
        for <gclcip-std-proposals@m.gmane.org>; Mon, 23 Mar 2015 14:30:35 -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
         :content-type:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=ZJ9eqlUEPj9SZJGXBxAjo6lRbYHXWxFSXqTGDt+OQos=;
        b=cS0xas+aNJSLMxXrAOHQjOwE0rNovkQhEYFM9oo1xQ3iQlbuwYxOBzSyznaCflX+BA
         MO8DcPhuCK5JDJoUCy6mJ2IpSgHWUgMGyojDBxmu+0Q7WFpHAJ3lGv+bDvm854aVeXWv
         FnUiiqYEZJR66mpENPvz9Ior4bmq26tXs4XnG/ROyXvXLBOaZurbbGwk/Em0o+QO+hJS
         Misw4dX/dI83XVrXxGBY3bAFReCua7hgxxHtkZwershPvWByScFcbVISGQxaog/2UA+N
         Y2FRLF/M//jb4bC2ImjDQ08V0EndAEIgLymBbeaBqHK5NU0mfg4MI/uwGzmEsFBeAbVd
         RuCg==
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:content-type:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=ZJ9eqlUEPj9SZJGXBxAjo6lRbYHXWxFSXqTGDt+OQos=;
        b=eP8DuSIksMEidGaO9IZpeXBN133YNIRGLeruBr71pfTg7Eysw96b084oy6gwwIPy9w
         dZCbZCWYm2/VnEG+AwMCS20TgzrXDhznQr7tDki5xg5NqdqTCqA+UCQT5k0UAczm8yju
         ekVWzgKRBeJ+qe0D5ViU2IDQ0oQyHvbbRs22NgjsI5ik/vRYbSzJRks3VRbsX2joi4gO
         /R1ZbNnRYD10HMom2AHr2Q/pbCTxrq0HfTwKtarm1uzeJySdCow5zR3UCxn3XYAFDfwt
         EzcIiNgvxFyTJsyATuyyU+fkhkdoI8sc1Dwfqt95EvX1c8fmQJGVNKPJX4aAKX+gdF1z
         F9KA==
X-Gm-Message-State: ALoCoQk1cqgMm9YMNEaVwKXuR7DpmEhv837HWqbeAKBp44K7eOCKWyKcbVcKf1CeGnSHRrs3OoQ+
X-Received: by 10.182.22.138 with SMTP id d10mr1381610obf.37.1427146235116;
        Mon, 23 Mar 2015 14:30:35 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.6.209 with SMTP id f78ls1961195ioi.13.gmail; Mon, 23 Mar
 2015 14:30:34 -0700 (PDT)
X-Received: by 10.50.56.17 with SMTP id w17mr358644igp.1.1427146234409;
        Mon, 23 Mar 2015 14:30:34 -0700 (PDT)
In-Reply-To: <2096343.oZu43OOe1O@tjmaciei-mobl4>
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:17127
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17127>

------=_Part_5147_276563614.1427146233529
Content-Type: multipart/alternative; 
	boundary="----=_Part_5148_142679684.1427146233529"

------=_Part_5148_142679684.1427146233529
Content-Type: text/plain; charset=UTF-8

I've wanted a "static virtual" concept just for convenience reasons to 
solve similar problems.  The point would just be to avoid having to have a 
secondary static function.

enum class Type : int
{
    SHOE,
};

struct Merchandise
{
    virtual Type GetType() const = 0;
};

struct Shoe : public Merchandise
{
    static virtual Type GetType() const override { return Type::SHOE; }
};

Type type1 = Shoe().GetType();
Type type2 = Shoe::GetType();
assert(type1 == type2);

One possible implementation would be to still be a "thiscall" function, 
whatever that means to the implementation, but ignoring the "this" 
parameter.  Shoe::GetType() could then pass nullptr as this.  Another 
possible implementation is to emit two functions of different mangled 
names, one static and one virtual.  Either implementation would work fine.

Rules as I imagine them:

1. Destructors can't be static virtual.
2. static virtual functions cannot reference this.  (obvious)
3. The static attribute is not heritable: a non-static virtual function may 
override a static virtual function.

Possible solutions to the function pointer problem:
4a. It is not possible to get a non-member pointer to a static virtual 
function.
--or--
4b. Ampersand-prefixed member pointer expressions (I don't remember their 
formal name)--i.e., &Shoe::GetType--would disambiguate member function 
pointer and non-member function pointer by context, like occurs for 
overloaded functions.

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_5148_142679684.1427146233529
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I've wanted a "static virtual" concept just for convenienc=
e reasons to solve similar problems.&nbsp; The point would just be to avoid=
 having to have a secondary static function.<br><br><div class=3D"prettypri=
nt" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 1=
87, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"><=
code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">enum</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">Type</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; SHOE</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pret=
tify">Merchandise</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbs=
p; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
virtual</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #606;" class=3D"styled-by-prettify">Type</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">GetType</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">=
0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" c=
lass=3D"styled-by-prettify">Shoe</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">pub=
lic</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #606;" class=3D"styled-by-prettify">Merchandise</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></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: #008;" class=3D"styled-by-prettify">static</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">virtual</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;"=
 class=3D"styled-by-prettify">Type</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"style=
d-by-prettify">GetType</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">const=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">override</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">return</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styl=
ed-by-prettify">Type</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
">SHOE</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #606;" c=
lass=3D"styled-by-prettify">Type</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> type1 </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">Shoe</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(=
).</span><span style=3D"color: #606;" class=3D"styled-by-prettify">GetType<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span s=
tyle=3D"color: #606;" class=3D"styled-by-prettify">Type</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> type2 </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #606;" c=
lass=3D"styled-by-prettify">Shoe</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #606;" class=3D"styl=
ed-by-prettify">GetType</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
assert</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">type1 </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">=3D=3D</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> type2</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><br=
>One possible implementation would be to still be a "thiscall" function, wh=
atever that means to the implementation, but ignoring the "<span style=3D"f=
ont-family: courier new,monospace;">this</span>" parameter.&nbsp; <span sty=
le=3D"font-family: courier new,monospace;">Shoe::GetType()</span> could the=
n pass <span style=3D"font-family: courier new,monospace;">nullptr</span> a=
s <span style=3D"font-family: courier new,monospace;">this</span>.&nbsp; An=
other possible implementation is to emit two functions of different mangled=
 names, one static and one virtual.&nbsp; Either implementation would work =
fine.<br><br>Rules as I imagine them:<br><br>1. Destructors can't be <span =
style=3D"font-family: courier new,monospace;">static virtual</span>.<br>2. =
<span style=3D"font-family: courier new,monospace;">static virtual</span> f=
unctions cannot reference <span style=3D"font-family: courier new,monospace=
;">this</span>.&nbsp; (obvious)<br>3. The <span style=3D"font-family: couri=
er new,monospace;">static</span> attribute is not heritable: a non-<span st=
yle=3D"font-family: courier new,monospace;">static virtual</span> function =
may override a <span style=3D"font-family: courier new,monospace;">static v=
irtual</span> function.<br><br>Possible solutions to the function pointer p=
roblem:<br>4a. It is not possible to get a non-member pointer to a <span st=
yle=3D"font-family: courier new,monospace;">static virtual</span> function.=
<br>--or--<br>4b. Ampersand-prefixed member pointer expressions (I don't re=
member their formal name)--i.e., <span style=3D"font-family: courier new,mo=
nospace;">&amp;Shoe::GetType</span>--would disambiguate member function poi=
nter and non-member function pointer by context, like occurs for overloaded=
 functions.<br><br>Melissa<br></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_5148_142679684.1427146233529--
------=_Part_5147_276563614.1427146233529--

.
