220 17114 <04122f67-f4cd-457c-902e-589091f90063@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: jgottman6@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: virtual constexpr fields
Date: Fri, 20 Mar 2015 18:39:26 -0700 (PDT)
Lines: 150
Approved: news@gmane.org
Message-ID: <04122f67-f4cd-457c-902e-589091f90063@isocpp.org>
References: <532355906.19321.1426710347371.JavaMail.yahoo@mail.yahoo.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1232_861976290.1426901966993"
X-Trace: ger.gmane.org 1426901979 16354 80.91.229.3 (21 Mar 2015 01:39:39 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 21 Mar 2015 01:39:39 +0000 (UTC)
Cc: c++std-ext@accu.org, ehsan@mozilla.com, botond_ballo@yahoo.ca, 
	botond_ballo@yahoo.ca
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD7LHGWIQEPRBT4XWOUAKGQEQ5D6ZOY@isocpp.org Sat Mar 21 02:39:38 2015
Return-path: <std-proposals+bncBD7LHGWIQEPRBT4XWOUAKGQEQ5D6ZOY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f200.google.com ([209.85.214.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD7LHGWIQEPRBT4XWOUAKGQEQ5D6ZOY@isocpp.org>)
	id 1YZ8Nv-0002Ss-1q
	for gclcip-std-proposals@m.gmane.org; Sat, 21 Mar 2015 02:39:31 +0100
Original-Received: by obcva2 with SMTP id va2sf156212431obc.0
        for <gclcip-std-proposals@m.gmane.org>; Fri, 20 Mar 2015 18:39:29 -0700 (PDT)
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:content-type:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=MIZT8S7tHTArt/wgdW1SkHNVBD90+VW0aXVKomSCDbs=;
        b=vOFdzNIdaNz5Pn/X3fg0aaYm8tiGttAVKhir1UJDdwEBrRhjEsGzrTqj19HE/d49MD
         s0GnNQc3Sdvn90zjkLyqVX1MnE2hXpjZuOVZCBXx1irYgZxOn39HwLCc7tGsGvmr2qBh
         Zbl3AeY/iZIRlUNI8/uEwHAw0k3m/tgG8LjnWXFsaLxrvzevfu/dMfWswsGunxdSjXGw
         SVyw1M3/4uCjHzpY1Mm/c39ZnlyHQoXyr6y0CwXUPt98d1PVzIFQ0x2xHvhVs91YJ142
         +C5fQmmrfQoN0RTOTvZAVfHtI5VrqF7XTQ1IVTz6qs/ulXeMhA5ufn0R8v3bvNrrkEWV
         cOqg==
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:content-type:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=MIZT8S7tHTArt/wgdW1SkHNVBD90+VW0aXVKomSCDbs=;
        b=O7OuZ/dlf0SfjpjUXFXzsxvVERyDyFdAO+dl2bufqZdvcxwkQ089RVFkpc1FsoRp/0
         WoK3DXTQN5qErd+Kb8LV+pjjKtBTBNi8+5q5MMl8jaS8jtvh6sgIyexwGs8a5sd34oy/
         +LZL09+CM5/Hf/2qNsoTSPa6kTGjsKH1cCvvHMEg1mY6CD065u2frO04eMozLR3NCawh
         FBAs4S7+PJEgwlumCFqcZzugG2hJ26i4/bH8l48TxJK7zHUGUUrjus2F9lM1BtM1FYah
         aAGnkti6bNx4TkimKMpo+jwgY1I0d1kF5vq1SiX3RalpKkmM3icX+pLT79zoARfX0JwI
         Qbfw==
X-Gm-Message-State: ALoCoQkNI+PHFdJYazDruJwc6jUcE9Sz2RsLBNIOCayYdLDUxdKJYzXfoyKPo+s1XWync4TAxQbI
X-Received: by 10.182.126.168 with SMTP id mz8mr96213525obb.9.1426901969692;
        Fri, 20 Mar 2015 18:39:29 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.68.103 with SMTP id v7ls939283obt.57.gmail; Fri, 20 Mar
 2015 18:39:27 -0700 (PDT)
X-Received: by 10.182.131.135 with SMTP id om7mr709505obb.7.1426901967727;
        Fri, 20 Mar 2015 18:39:27 -0700 (PDT)
In-Reply-To: <532355906.19321.1426710347371.JavaMail.yahoo@mail.yahoo.com>
X-Original-Sender: jgottman6@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:17114
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/17114>

------=_Part_1232_861976290.1426901966993
Content-Type: multipart/alternative; 
	boundary="----=_Part_1233_310823368.1426901966993"

------=_Part_1233_310823368.1426901966993
Content-Type: text/plain; charset=UTF-8

Another, possibly simpler way of achieving the same effect is to weaken the 
rule that virtual functions can't be constexpr.  If we say that *final *virtual 
functions can be final, then we can define Shoe::price as


struct Shoe : Merchandise {
    constexpr int price() override final { return 10;
}

This would be perfectly safe, because the compiler could always compute 
Shoe::price() without having to look at a vtable.

Joe Gottman



On Wednesday, March 18, 2015 at 4:25:51 PM UTC-4, Botond Ballo wrote:
>
> There are cases where you would like to associate constants with a given 
> type. Here is how you can currently do it in C++:
>
> struct Merchandise {
>     virtual int price() { return 0; }
> };
>
> struct Shoe : Merchandise {
>     virtual int price() { return 10;
> }
>
> If you could do it this way instead:
>
> struct Merchandise {
>     virtual constexpr int price = 0;
> };
>
> struct Shoe : Merchandise {
>     virtual constexpr int price = 10;
> }
>
> then the compiler could store the constant value directly in the vtable. 
> This would eliminate the double indirection involved in dereferencing a 
> function vtable entry, the cost of running that function at runtime, and 
> the code size of the function in the compiled binary.
>
> Virtual fields would be limited to being constexpr, so that the value to 
> be placed in the vtable, like other values in the vtable, can be determined 
> at compile time.
>
> Has this, or something similar, ever been proposed? Is there any interest 
> in it?
>
> -- Botond and Ehsan
>
>

-- 

--- 
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_1233_310823368.1426901966993
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Another, possibly simpler way of achieving the same effect=
 is to weaken the rule that virtual functions can't be constexpr.&nbsp; If =
we say that <i>final </i>virtual functions can be final, then we can define=
 Shoe::price as<br><br><div class=3D"prettyprint" style=3D"background-color=
: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid=
; border-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><d=
iv class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Shoe</sp=
an><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"> </span><span style=3D"color: #6=
06;" class=3D"styled-by-prettify">Merchandise</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">constexpr</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">int</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> price</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">override</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">final</span><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"> </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pre=
ttify">10</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></div></=
code></div><br>This would be perfectly safe, because the compiler could alw=
ays compute Shoe::price() without having to look at a vtable.<br><br>Joe Go=
ttman<br><br><br><br>On Wednesday, March 18, 2015 at 4:25:51 PM UTC-4, Boto=
nd Ballo wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-=
left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div><div style=
=3D"color:#000;background-color:#fff;font-family:HelveticaNeue,Helvetica Ne=
ue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:12px"><div dir=3D"ltr=
">There are cases where you would like to associate constants with a given =
type. Here is how you can currently do it in C++:<br><br>struct Merchandise=
 {<br>&nbsp;&nbsp;&nbsp; virtual int price() { return 0; }<br>};<br><br>str=
uct Shoe : Merchandise {<br>&nbsp;&nbsp;&nbsp; virtual int price() { return=
 10;<br>}<br><br>If you could do it this way instead:<br><br>struct Merchan=
dise {<br>&nbsp;&nbsp;&nbsp; virtual constexpr int price =3D 0;<br>};<br><b=
r>struct Shoe : Merchandise {<br>&nbsp;&nbsp;&nbsp; virtual constexpr int p=
rice =3D 10;<br>}<br><br>then the compiler could store the constant value d=
irectly in the vtable. This would eliminate the double indirection involved=
 in dereferencing a function vtable entry, the cost of running that functio=
n at runtime, and the code size of the function in the compiled binary.<br>=
<br>Virtual fields would be limited to being constexpr, so that the value t=
o be placed in the vtable, like other values in the vtable, can be determin=
ed at compile time.<br><br>Has this, or something similar, ever been propos=
ed? Is there any interest in it?<br><br>-- Botond and Ehsan<br></div><div d=
ir=3D"ltr"><br></div></div></div></blockquote></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_1233_310823368.1426901966993--
------=_Part_1232_861976290.1426901966993--

.
