220 31757 <b9d7e28d-325b-b760-e021-ef087d0b56f3@scylladb.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Avi Kivity <avi@scylladb.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Allow constexpr static data members in a
 literal type.
Date: Sun, 26 Mar 2017 17:49:16 +0300
Organization: ScyllaDB
Lines: 236
Approved: news@gmane.org
Message-ID: <b9d7e28d-325b-b760-e021-ef087d0b56f3@scylladb.com>
References: <dfb9f65c-ea1d-e92b-85e0-333efed1aec5@scylladb.com>
 <470f86cc-36b7-4244-82dd-b795af107996@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------A9BDFBD26DF6F56B77F8A6FF"
X-Trace: blaine.gmane.org 1490539764 30367 195.159.176.226 (26 Mar 2017 14:49:24 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 26 Mar 2017 14:49:24 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.8.0
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDHJFOWD7YCRB4FJ37DAKGQETENWCKY@isocpp.org Sun Mar 26 16:49:19 2017
Return-path: <std-proposals+bncBDHJFOWD7YCRB4FJ37DAKGQETENWCKY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f69.google.com ([209.85.215.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDHJFOWD7YCRB4FJ37DAKGQETENWCKY@isocpp.org>)
	id 1cs9Tn-00071M-I9
	for gclcip-std-proposals@m.gmane.org; Sun, 26 Mar 2017 16:49:15 +0200
Original-Received: by mail-lf0-f69.google.com with SMTP id u72sf14650659lfg.19
        for <gclcip-std-proposals@m.gmane.org>; Sun, 26 Mar 2017 07:49:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=subject:to:references:from:organization:message-id:date:user-agent
         :mime-version:in-reply-to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=4UaqLiZZB4Up7bqqdgZyBEIspO3UUdfSvNDBfiGorJQ=;
        b=GdBnyG+2vtewJBUOnfsgGrcSbtsH57b2jcTjfNaa8IY720A4NAgV75aLGglYxh9sUA
         8IqtdQDHHxxuvZrtdiii9vdwvAWYjuQ2/lS8ihIPCF5bXqj7CMm01v1JnxDeBcNNBpOd
         wJpYZkvXSI1F9tTRQ1aztnGg0xAm62CKQ4PIzT/rzZ8Ij0LUPRPa2cYs54JzoGrf9cLN
         WVNkJhNjarEivQ5XU1U5TjWHPpm5qgGGZKz/OriH8Yw0hglxCAcOPR7txv3/2NLO6LMw
         gnccvTVL0dHE0mwLl38qdpJehn3cn5w6LJeeFJ/PjmMfJjej7IHPL0tdwCoKoU6MnmEF
         V5tg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:subject:to:references:from:organization
         :message-id:date:user-agent:mime-version:in-reply-to
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=4UaqLiZZB4Up7bqqdgZyBEIspO3UUdfSvNDBfiGorJQ=;
        b=eMBA3f2IqAAl7ghumr+33BuvMq120/sxPkqWsvqYR4xlPYk1lc0NEq0E2jlQcxiV3g
         lXJIWDdNdhmJCZ3cvKgbNCnpkMKpR5EwtC0rA+rK1tyyu9nqDiBgNYUcV2LvXafXG8k8
         z76r0qyLfYVCR0C4WFMnvB9jsEw6s/gSn2XeexuMw0weZ4/LDebcp2/T3h8IrLLLEBDV
         24pusJRAboEPgeTneIbAhlAvOxOGFkddW6n3dh9itZC/syEAj+snQGtnmG2yZFcr1uAB
         GYJl5oQPfDedEfy90Si5lvoKy9ZS9O5LbXVgNHV7ePu2BQGYLL5xzQ/n0/s9N86qHd7b
         RvPQ= 
X-Gm-Message-State: AFeK/H06dzxi39uDAqZkcwCriOf2T57/eIaikP7AlmI977KVlxNIDUcOYeOv2rUDEe4KuQ==
X-Received: by 10.25.32.142 with SMTP id g136mr2192533lfg.12.1490539761658;
        Sun, 26 Mar 2017 07:49:21 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.208.1 with SMTP id h1ls956782wmg.16.gmail; Sun, 26 Mar 2017
 07:49:20 -0700 (PDT)
X-Received: by 10.223.131.133 with SMTP id 5mr15202426wre.183.1490539760277;
        Sun, 26 Mar 2017 07:49:20 -0700 (PDT)
Original-Received: from mail-wr0-x22a.google.com (mail-wr0-x22a.google.com. [2a00:1450:400c:c0c::22a])
        by mx.google.com with ESMTPS id l9si1625117wre.335.2017.03.26.07.49.20
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 26 Mar 2017 07:49:20 -0700 (PDT)
Received-SPF: pass (google.com: domain of avi@scylladb.com designates 2a00:1450:400c:c0c::22a as permitted sender) client-ip=2a00:1450:400c:c0c::22a;
Original-Received: by mail-wr0-x22a.google.com with SMTP id l43so22492970wre.1
        for <std-proposals@isocpp.org>; Sun, 26 Mar 2017 07:49:20 -0700 (PDT)
X-Received: by 10.28.135.21 with SMTP id j21mr5443962wmd.70.1490539759995;
        Sun, 26 Mar 2017 07:49:19 -0700 (PDT)
Original-Received: from avi.cloudius-systems.com ([37.142.229.250])
        by smtp.gmail.com with ESMTPSA id n80sm8374901wrb.24.2017.03.26.07.49.18
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 26 Mar 2017 07:49:19 -0700 (PDT)
In-Reply-To: <470f86cc-36b7-4244-82dd-b795af107996@isocpp.org>
X-Original-Sender: avi@scylladb.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@scylladb-com.20150623.gappssmtp.com;       spf=pass (google.com:
 domain of avi@scylladb.com designates 2a00:1450:400c:c0c::22a as permitted
 sender) smtp.mailfrom=avi@scylladb.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: <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:31757
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/31757>

This is a multi-part message in MIME format.
--------------A9BDFBD26DF6F56B77F8A6FF
Content-Type: text/plain; charset=UTF-8; format=flowed



On 03/26/2017 05:35 PM, Nicol Bolas wrote:
> On Sunday, March 26, 2017 at 10:30:29 AM UTC-4, Avi Kivity wrote:
>
>     Consider this type-safe bool class:
>
>
>        template <typename Tag>
>
>        class bool_class {
>
>            bool _value;
>
>        public:
>
>            explicit constexpr bool_class(bool v) noexcept : _value(v) {}
>
>            // more emulation of bool
>
>            static constexpr bool_class yes = bool_class{true};
>
>            static constexpr bool_class no = bool_class{true};
>
>        };
>
>
>     Compilation fails, I believe rightly, on clang, because by the
>     time yes
>     and no are parsed, bool_class is an incomplete type, and therefore
>     not a
>     literal type.  It could be worked around by making yes and no
>     functions.
>
>     Should we make this legal?  It seems reasonable for types to offer
>     constants scoped under their own name, and if they are literal types,
>     that these constants can be constexpr.
>
>
> How does it seem reasonable to define variables of a type that has not 
> yet been defined?


You can do that already, within an inline member function.

> What's wrong with defining them outside of the scope of the class?
>

You have to invent a scope for them.

Perhaps

    template <typename Tag>

    class bool_class {

        bool _value;

    public:

        explicit constexpr bool_class(bool v) noexcept : _value(v) {}

        // more emulation of bool

        struct constants;

    };


    template <typenamer Tag>
    struct bool_class<Tag>::constants {
        static constexpr bool_class yes = bool_class{true};

        static constexpr bool_class no = bool_class{true};
    };

But using them is awkward and artificial.

-- 
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/b9d7e28d-325b-b760-e021-ef087d0b56f3%40scylladb.com.

--------------A9BDFBD26DF6F56B77F8A6FF
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html>
  <head>
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <p><br>
    </p>
    <br>
    <div class=3D"moz-cite-prefix">On 03/26/2017 05:35 PM, Nicol Bolas
      wrote:<br>
    </div>
    <blockquote
      cite=3D"mid:470f86cc-36b7-4244-82dd-b795af107996@isocpp.org"
      type=3D"cite">
      <div dir=3D"ltr">On Sunday, March 26, 2017 at 10:30:29 AM UTC-4, Avi
        Kivity wrote:
        <blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:
          0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Consider
          this type-safe bool class:
          <br>
          <br>
          <br>
          =C2=A0 =C2=A0template &lt;typename Tag&gt;
          <br>
          <br>
          =C2=A0 =C2=A0class bool_class {
          <br>
          <br>
          =C2=A0 =C2=A0 =C2=A0 =C2=A0bool _value;
          <br>
          <br>
          =C2=A0 =C2=A0public:
          <br>
          <br>
          =C2=A0 =C2=A0 =C2=A0 =C2=A0explicit constexpr bool_class(bool v) =
noexcept :
          _value(v) {}
          <br>
          <br>
          =C2=A0 =C2=A0 =C2=A0 =C2=A0// more emulation of bool
          <br>
          <br>
          =C2=A0 =C2=A0 =C2=A0 =C2=A0static constexpr bool_class yes =3D bo=
ol_class{true};
          <br>
          <br>
          =C2=A0 =C2=A0 =C2=A0 =C2=A0static constexpr bool_class no =3D boo=
l_class{true};
          <br>
          <br>
          =C2=A0 =C2=A0};
          <br>
          <br>
          <br>
          Compilation fails, I believe rightly, on clang, because by the
          time yes <br>
          and no are parsed, bool_class is an incomplete type, and
          therefore not a <br>
          literal type. =C2=A0It could be worked around by making yes and n=
o
          functions.
          <br>
          <br>
          Should we make this legal? =C2=A0It seems reasonable for types to
          offer <br>
          constants scoped under their own name, and if they are literal
          types, <br>
          that these constants can be constexpr.<br>
        </blockquote>
        <div><br>
          How does it seem reasonable to define variables of a type that
          has not yet been defined? </div>
      </div>
    </blockquote>
    <br>
    <br>
    You can do that already, within an inline member function.<br>
    <br>
    <blockquote
      cite=3D"mid:470f86cc-36b7-4244-82dd-b795af107996@isocpp.org"
      type=3D"cite">
      <div dir=3D"ltr">
        <div>What's wrong with defining them outside of the scope of the
          class?<br>
        </div>
      </div>
      <br>
    </blockquote>
    <br>
    You have to invent a scope for them.<br>
    <br>
    Perhaps<br>
    <br>
    =C2=A0=C2=A0 template &lt;typename Tag&gt;<br>
    <br>
    =C2=A0=C2=A0 class bool_class {<br>
    <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bool _value;<br>
    <br>
    =C2=A0=C2=A0 public:<br>
    <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 explicit constexpr bool_class(bool=
 v) noexcept : _value(v) {}<br>
    <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // more emulation of bool<br>
    <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct constants;<br>
    <br>
    =C2=A0=C2=A0 }; <br>
    <br>
    <br>
    =C2=A0=C2=A0 template &lt;typenamer Tag&gt;<br>
    =C2=A0=C2=A0 struct bool_class&lt;Tag&gt;::constants {<br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 static constexpr bool_class yes =
=3D bool_class{true};<br>
    <br>
    =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 static constexpr bool_class no =3D=
 bool_class{true};<br>
    =C2=A0=C2=A0 };<br>
    <br>
    But using them is awkward and artificial.<br>
    <br>
  </body>
</html>

<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/b9d7e28d-325b-b760-e021-ef087d0b56f3%=
40scylladb.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.googl=
e.com/a/isocpp.org/d/msgid/std-proposals/b9d7e28d-325b-b760-e021-ef087d0b56=
f3%40scylladb.com</a>.<br />

--------------A9BDFBD26DF6F56B77F8A6FF--

.
