220 13025 <B064489C-6BF8-4687-A5F0-E0242A6257C5@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Compile-time static `std::integral_counter`
Date: Sat, 20 Sep 2014 07:32:29 +0800
Lines: 103
Approved: news@gmane.org
Message-ID: <B064489C-6BF8-4687-A5F0-E0242A6257C5@gmail.com>
References: <9a0bde7b-2f0a-4a5b-92a4-88d5e8df7ea9@isocpp.org> <B686551F-D10C-4107-9EAB-6487A7128F3F@gmail.com> <b91aef20-a4ca-4b17-ae8f-4553fc76a0de@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_48C506D6-33DF-4AC5-9FC9-9883D2C39E0D"
X-Trace: ger.gmane.org 1411169571 7089 80.91.229.3 (19 Sep 2014 23:32:51 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 19 Sep 2014 23:32:51 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBGX26KQAKGQECX4UCMA@isocpp.org Sat Sep 20 01:32:44 2014
Return-path: <std-proposals+bncBCW25A7E3QCRBGX26KQAKGQECX4UCMA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ig0-f200.google.com ([209.85.213.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBGX26KQAKGQECX4UCMA@isocpp.org>)
	id 1XV7fQ-00019r-3d
	for gclcip-std-proposals@m.gmane.org; Sat, 20 Sep 2014 01:32:44 +0200
Original-Received: by mail-ig0-f200.google.com with SMTP id hn15sf2314272igb.7
        for <gclcip-std-proposals@m.gmane.org>; Fri, 19 Sep 2014 16:32:43 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:mime-version:subject:date
         :references:to:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=x9uuzdtvQZUFT+5xf/XEhZr/JYwv5h58WFWbCr9KMu0=;
        b=VJdTSN/XPsIKjEyrR5PrXRERfSpNhNDxZBskKUcUMDrbU4T7J7uDHNUta+jwUaoJRE
         tsbPjJo9uZ5vOpTLoUcQKvRv1BQmGwLMvmsPVoBwTTG8u3/RCzoVyh7S3KhoHrCxKS24
         +HlZX5YYG2vQu0+d+zVzAybQQjdZKz1x20WdJ9kLunWA34OnXEl7yLyg8YjHqhVIFhap
         E9+NGGezYa9SBWakQ45kCJ9MWSpqkrH2FIeUF/ktdsFfBsFD5TDy7O+mSzjdtCCqq3Le
         +A4Uc/qEtS7DL3sBNLoEZWYioLqWL7gmhZmQeUnfJbmdY8HG5FUEggrdI4en1no9xcRH
         r5nQ==
X-Gm-Message-State: ALoCoQlHZQcfjLPWaSILarmaxMJNHfFO+e/dVaL51WUarZ3ycXnf+8GupwaSVUR2G9hRa5wAbR4k
X-Received: by 10.43.71.81 with SMTP id yj17mr13554970icb.26.1411169563233;
        Fri, 19 Sep 2014 16:32:43 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.61.148 with SMTP id p20ls752144igr.38.canary; Fri, 19 Sep
 2014 16:32:42 -0700 (PDT)
X-Received: by 10.68.106.162 with SMTP id gv2mr4483651pbb.17.1411169562299;
        Fri, 19 Sep 2014 16:32:42 -0700 (PDT)
Original-Received: from mail-pd0-x229.google.com (mail-pd0-x229.google.com [2607:f8b0:400e:c02::229])
        by mx.google.com with ESMTPS id d8si5052786pat.120.2014.09.19.16.32.42
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 19 Sep 2014 16:32:42 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c02::229 as permitted sender) client-ip=2607:f8b0:400e:c02::229;
Original-Received: by mail-pd0-f169.google.com with SMTP id w10so823447pde.0
        for <std-proposals@isocpp.org>; Fri, 19 Sep 2014 16:32:42 -0700 (PDT)
X-Received: by 10.66.139.106 with SMTP id qx10mr5751253pab.126.1411169562163;
        Fri, 19 Sep 2014 16:32:42 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.54.151])
        by mx.google.com with ESMTPSA id w11sm2811020pbt.84.2014.09.19.16.32.39
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 19 Sep 2014 16:32:41 -0700 (PDT)
In-Reply-To: <b91aef20-a4ca-4b17-ae8f-4553fc76a0de@isocpp.org>
X-Mailer: Apple Mail (2.1878.6)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:400e:c02::229 as permitted
 sender) smtp.mail=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=NONE dis=NONE) header.from=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:13025
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/13025>

--Apple-Mail=_48C506D6-33DF-4AC5-9FC9-9883D2C39E0D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On 2014-09-20, at 1:40 AM, Vittorio Romeo <vittorio.romeo.vee@gmail.com> wr=
ote:

> On Friday, 19 September 2014 19:23:22 UTC+2, David Krauss wrote:
> I see some discussion of the ODR in this thread. Any counter usage with l=
inkage does need to be placed in the header file and repeated exactly the s=
ame in each TU. Avoid sharing a counter between headers unless those header=
s are all-or-nothing.
>=20
> Can you elaborate more on this? What I am currently doing is putting the =
workaround code in an header file (header-only library) and using inline in=
 every function. Is that not guaranteed to return expected values in differ=
ent TUs? (values that never repeat, I mean)

It's in reference to the StackOverflow answer.

If the counter values are assigned at runtime, it's sufficient to have exte=
rnal linkage (inline or not) on some object or function which does the coun=
ting. This should also be mutex-locked, because each TU is allowed to be in=
itialized in a different thread.

If the counter values are assigned at compile time, you need to compute eac=
h value immediately as the counter updates are declared within the TU. Othe=
r TUs are invisible until linking. In order to have consistent counter valu=
es, the counting and assignment of the counter to whatever variables need t=
o be the same across all TUs that observe the counter or those variables.

There is no way to "peek" at things in another TU, because that information=
 doesn't exist. Maybe the next TU hasn't even be written yet by a programme=
r. inline certainly won't help.

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--Apple-Mail=_48C506D6-33DF-4AC5-9FC9-9883D2C39E0D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On 2014&=
ndash;09&ndash;20, at 1:40 AM, Vittorio Romeo &lt;<a href=3D"mailto:vittori=
o.romeo.vee@gmail.com">vittorio.romeo.vee@gmail.com</a>&gt; wrote:</div><br=
 class=3D"Apple-interchange-newline"><blockquote type=3D"cite"><div dir=3D"=
ltr"><font size=3D"1">On Friday, 19 September 2014 19:23:22 UTC+2, David Kr=
auss  wrote:</font><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0=
px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204)=
; border-left-style: solid; padding-left: 1ex; position: static; z-index: a=
uto;"><div style=3D"word-wrap:break-word"><font size=3D"1">I see some discu=
ssion of the ODR in this thread. Any counter usage with linkage does need t=
o be placed in the header file and repeated exactly the same in each TU. Av=
oid sharing a counter between headers unless those headers are all-or-nothi=
ng.</font></div></blockquote><div><br></div><div>Can you elaborate more on =
this? What I am currently doing is putting the workaround code in an header=
 file (header-only library) and using inline in every function. Is that not=
 guaranteed to return expected values in different TUs? (values that never =
repeat, I mean)</div></div></blockquote><br></div><div>It&rsquo;s in refere=
nce to the StackOverflow answer.</div><div><br></div><div>If the counter va=
lues are assigned at runtime, it&rsquo;s sufficient to have external linkag=
e (inline or not) on some object or function which does the counting. This =
should also be mutex-locked, because each TU is allowed to be initialized i=
n a different thread.</div><div><br></div><div>If the counter values are as=
signed at compile time, you need to compute each value immediately as the c=
ounter updates are declared within the TU. Other TUs are invisible until li=
nking. In order to have consistent counter values, the counting and assignm=
ent of the counter to whatever variables need to be the same across all TUs=
 that observe the counter or those variables.</div><div><br></div>There is =
no way to &ldquo;peek&rdquo; at things in another TU, because that informat=
ion doesn&rsquo;t exist. Maybe the next TU hasn&rsquo;t even be written yet=
 by a programmer. <font face=3D"Courier">inline</font> certainly won&rsquo;=
t help.<div><br></div></body></html>

<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 />

--Apple-Mail=_48C506D6-33DF-4AC5-9FC9-9883D2C39E0D--

.
