220 5132 <9a4c139d-b08f-4dab-b5a3-9ff9d3139061@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Jonathan Wakely <cxx@kayari.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: constexpr data member
Date: Wed, 19 Jun 2013 14:26:16 -0700 (PDT)
Lines: 157
Approved: news@gmane.org
Message-ID: <9a4c139d-b08f-4dab-b5a3-9ff9d3139061@isocpp.org>
References: <CAGsORuDonz16fG51JaLgDCHptjpZAnuWM2AgNrBN_44hxUqjXA@mail.gmail.com>
 <300a19dd-8a82-4788-9802-45170480b30a@isocpp.org>
 <CAGsORuBWr7F6wpyUd1mBFDKGU7P9jKaPaq+wOYDpFL6QGH7Byw@mail.gmail.com>
 <63d90b03-5605-476d-b40b-7ebcee0d3354@isocpp.org>
 <CAGsORuD58nw+76_2_pp6GqpwGKhbVHJ40wnCZccrUXRjxB_qNQ@mail.gmail.com>
 <cf218cdb-bfda-46e7-bedb-23795ace1ae3@isocpp.org>
 <CAGsORuAMLbeFJZwrjmaMV6AF7rop==h8BJiGiBAtgxQxO7E++g@mail.gmail.com>
 <0df105c5-7019-4674-83ac-1b071964210b@isocpp.org>
 <CAGsORuCmGnrUg+hkXCWssHp5KPu1wS+GsO__DwoDi13Y1UTDfA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_2660_28040039.1371677176331"
X-Trace: ger.gmane.org 1371677182 4967 80.91.229.3 (19 Jun 2013 21:26:22 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 19 Jun 2013 21:26:22 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCMONUNYS4IRB6GDRCHAKGQE4BXKVDA@isocpp.org Wed Jun 19 23:26:23 2013
Return-path: <std-proposals+bncBCMONUNYS4IRB6GDRCHAKGQE4BXKVDA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-gh0-f197.google.com ([209.85.160.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCMONUNYS4IRB6GDRCHAKGQE4BXKVDA@isocpp.org>)
	id 1UpPtS-0002su-8V
	for gclcip-std-proposals@m.gmane.org; Wed, 19 Jun 2013 23:26:18 +0200
Original-Received: by mail-gh0-f197.google.com with SMTP id r20sf4743863ghr.4
        for <gclcip-std-proposals@m.gmane.org>; Wed, 19 Jun 2013 14:26:17 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20120113;
        h=x-beenthere:date:from:to:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-google-group-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=YVpaZYqRhrv/FUztD0DAfmCqXiEfUzI1Z7Xve/5TUoU=;
        b=F00u4fVrgQ3MbV/3kuaW5ZSWoom4BXmKkwLGf/7gjq2nXzGR5fkmZJkWdhmJFXHUpZ
         4+GoDCxOFoun9AA+cjW4bRxH0vQ5PLw9242QN0WSPcU8xKJwUFoCQ2Bb8oE+nFv9Yy2+
         Z6MKsWerI58oIbplbhV3TV7WX1ejxAVF4o1Y0dG9Oxnykbb22mDZRMZAHjkKF8v06ieA
         +jrbewJhHthsoBj66F+JkCf1CayHY4108BudtnZJ7Zfj72hiGYjWLMtP/X4g6JQcTBmD
         0NoSzVcbrH6NyO/5YpVUPtIxZbrrWBGbHjJiRMlfvry34eEytPvn0OTLPRO//2KLJq3w
         bARA==
X-Received: by 10.224.129.196 with SMTP id p4mr5001243qas.6.1371677177318;
        Wed, 19 Jun 2013 14:26:17 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.4.138 with SMTP id k10ls463493qek.15.gmail; Wed, 19 Jun
 2013 14:26:16 -0700 (PDT)
X-Received: by 10.49.15.74 with SMTP id v10mr109542qec.16.1371677176634;
        Wed, 19 Jun 2013 14:26:16 -0700 (PDT)
In-Reply-To: <CAGsORuCmGnrUg+hkXCWssHp5KPu1wS+GsO__DwoDi13Y1UTDfA@mail.gmail.com>
X-Original-Sender: cxx@kayari.org
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: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:5132
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/5132>

------=_Part_2660_28040039.1371677176331
Content-Type: text/plain; charset=ISO-8859-1



On Wednesday, June 19, 2013 9:48:50 PM UTC+1, Zhihao Yuan wrote:
>
> On Wed, Jun 19, 2013 at 3:19 PM, Jonathan Wakely <c...@kayari.org<javascript:>> 
> wrote: 
> >> But a variable defined in namespace scope default to have external 
> >> linkage, then why a `const` qualifier can change its linkage? 
> > 
> > So that simple named constants in separate translation units don't 
> interfere 
> > and you don't have to be careful about avoiding name clashes. 
>
> So that simple named constants in class scope are not duplicated 
> for each object (not allowed, forever) and you don't have to care 
> about what the constants actually are. 
>

That's an argument in favour of static data members existing, not an 
argument in favour of constexpr implying static.

We already have them, they work fine, making constexpr imply static adds no 
new ability to the language and doesn't make it easier to express your 
designs.
 

> > OK, but what about the consistency of constexpr data members and 
> consexpr 
> > member functions? 
>
> Re-read your comment, consistency of a data member and a 
> member function -- for what?


For whether they are static or not, obviously.

struct A {
  static constexpr int one = 1;
  static constexpr int two() { return 2; }
};

If I want A::one() and A::two() to be constexpr, I say so. If I want them 
to be static, I say so.

You're proposing:

struct A {
  constexpr int one = 1;
  static constexpr int two() { return 2; }
};

If I glance at this code I do not immediately see that A::one is static. It 
looks like an instance variable.

That's what I mean by consistency.

Now consider:

struct A {
  const int zero = 0;
  constexpr int one = 1;
  static constexpr int two()  { return 2; }
  constexpr int three()  { return 3; }
};

Are you really suggesting that it makes the language easier to teach that 
A::zero is non-static and A::one is static?

How does your mental model of "constexpr means it's just a constant, you 
don't need to care about storage.linkage etc." help here? Why does it imply 
static on A::one but not A::three?  It's inconsistent.


-- 

--- 
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_2660_28040039.1371677176331
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<br><br>On Wednesday, June 19, 2013 9:48:50 PM UTC+1, Zhihao Yuan wrote:<bl=
ockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border=
-left: 1px #ccc solid;padding-left: 1ex;">On Wed, Jun 19, 2013 at 3:19 PM, =
Jonathan Wakely &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscate=
d-mailto=3D"hPnXCBwa4BIJ">c...@kayari.org</a>&gt; wrote:
<br>&gt;&gt; But a variable defined in namespace scope default to have exte=
rnal
<br>&gt;&gt; linkage, then why a `const` qualifier can change its linkage?
<br>&gt;
<br>&gt; So that simple named constants in separate translation units don't=
 interfere
<br>&gt; and you don't have to be careful about avoiding name clashes.
<br>
<br>So that simple named constants in class scope are not duplicated
<br>for each object (not allowed, forever) and you don't have to care
<br>about what the constants actually are.
<br></blockquote><div><br></div><div>That's an argument in favour of static=
 data members existing, not an argument in favour of constexpr implying sta=
tic.</div><div><br></div><div>We already have them, they work fine, making =
constexpr imply static adds no new ability to the language and doesn't make=
 it easier to express your designs.</div><div>&nbsp;</div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;">&gt; OK, but what about the consistency of cons=
texpr data members and consexpr
<br>&gt; member functions?
<br>
<br>Re-read your comment, consistency of a data member and a
<br>member function -- for what?</blockquote><div><br></div><div>For whethe=
r they are static or not, obviously.</div><div><br></div><div>struct A {</d=
iv><div>&nbsp; static constexpr int one =3D 1;</div><div>&nbsp; static cons=
texpr int two() { return 2; }</div><div>};</div><div><br></div><div>If I wa=
nt A::one() and A::two() to be constexpr, I say so. If I want them to be st=
atic, I say so.</div><div><br></div><div>You're proposing:</div><div><br></=
div><div><div>struct A {</div><div>&nbsp; constexpr int one =3D 1;</div><di=
v>&nbsp; static constexpr int two() { return 2; }</div><div>};</div></div><=
div><br></div><div>If I glance at this code I do not immediately see that A=
::one is static. It looks like an instance variable.</div><div><br></div><d=
iv>That's what I mean by consistency.</div><div><br></div><div>Now consider=
:</div><div><br></div><div><div><div>struct A {</div><div>&nbsp; const int =
zero =3D 0;</div><div>&nbsp; constexpr int one =3D 1;</div><div>&nbsp; stat=
ic constexpr int two() &nbsp;{ return 2; }</div><div>&nbsp; constexpr int t=
hree() &nbsp;{ return 3; }</div><div>};</div></div></div><div><br></div><di=
v>Are you really suggesting that it makes the language easier to teach that=
 A::zero is non-static and A::one is static?</div><div><br></div><div>How d=
oes your mental model of "constexpr means it's just a constant, you don't n=
eed to care about storage.linkage etc." help here? Why does it imply static=
 on A::one but not A::three? &nbsp;It's inconsistent.</div><div><br></div><=
div><br></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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_2660_28040039.1371677176331--

.
