220 41196 <7ab7b56f-e805-4703-a566-d805d08e20e2@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: cppljevans@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Proposal: Extensions of Scoped Enumerations
Date: Sun, 2 Dec 2018 08:25:53 -0800 (PST)
Lines: 227
Approved: news@gmane.org
Message-ID: <7ab7b56f-e805-4703-a566-d805d08e20e2@isocpp.org>
References: <506ba0a8-2d6b-4a4d-8fe8-b5e94d232365@isocpp.org>
 <82c331a0-fb81-4b67-8a7e-c5a6b8929e00@isocpp.org>
 <43b3f4ec-fd19-4144-bf24-067ce587e071@isocpp.org>
 <d54cc535-542f-4a7b-80f9-b4dab85e0ca4@isocpp.org>
 <9e3bba78-04c2-42d5-b522-2712932c1659@isocpp.org>
 <cffbc45a-406b-444b-a52f-64cedd955cbd@isocpp.org>
 <73866d3d-1466-3bca-55d2-3c00c16127a4@wanadoo.fr>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_3805_1739465788.1543767953717"
X-Trace: blaine.gmane.org 1543767831 6280 195.159.176.226 (2 Dec 2018 16:23:51 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 2 Dec 2018 16:23:51 +0000 (UTC)
Cc: philipgins@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDAYTI72VMGRBE4PSDQAKGQETNDYXZA@isocpp.org Sun Dec 02 17:23:47 2018
Return-path: <std-proposals+bncBDAYTI72VMGRBE4PSDQAKGQETNDYXZA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw1-f69.google.com ([209.85.161.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDAYTI72VMGRBE4PSDQAKGQETNDYXZA@isocpp.org>)
	id 1gTUX4-0001Um-AX
	for gclcip-std-proposals@m.gmane.org; Sun, 02 Dec 2018 17:23:46 +0100
Original-Received: by mail-yw1-f69.google.com with SMTP id y65sf7879105ywy.3
        for <gclcip-std-proposals@m.gmane.org>; Sun, 02 Dec 2018 08:25:56 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=5zrp/PzfazqQggzhLWFyZwcgzWIAXgRKv6jcYI2cpWA=;
        b=VkdNimRpNWnM0QTcKBL70JyFl3U7AnUmDlBnwTtwd443ooUm1J93pXGcdeB8rt0X/K
         KftUtdxCPHQw3zoyDwrLu1/4/Tnw0iC4JqMTTaaHLClIxbXheuzmn4SoGl6PWmkEYFvO
         OwdnJqhE8zVq5NFUU67joz4/gAw3qXfrqsE2KyA/1G+uw7v0yUhvVtStvDIs8/KSb57Y
         427AZTJj0uZ0bEwPcghjcHym4YZ5owJlPrEQoOKOxReMBFRRkj3vqRW3LZ1iLx/TZkmM
         0kxW8eGvjELYhYpeo3Gnre99AIh+EnF/u6uik1JRNOwRSUHG9UIiHqj4SdZ3Cua1aENd
         Ij3g==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=5zrp/PzfazqQggzhLWFyZwcgzWIAXgRKv6jcYI2cpWA=;
        b=cpkxfMFwZ2OwGxYhRmG7FSuoSCJuAZ5ki/tceOfnc4ZNiJ+gdqJL+juCXbwZVnObr4
         QeuSatQ2t9H+ypt7Oi818h2SgNZrH+2IJlQhuxTH8ufb5Ra69e7YTBcPWzIeYketNi+l
         WoWOU7DkNCHuE1GmFDnYIpIu/7MTnxr46RjM7ptiVF3P8Z+3FoNU/x0322haGRPVKYQu
         4ERUFd26PSj/aICl5N0sRg/i2LAnYBOydB6cGn3nIbWCrS+LY/d4jF102cUbjOtCfsSX
         N4rmDn5duNbcyVCsR7MQZDD+pYVSZ8BmLLsGFdyyBCQHDL8WipmimotxIsJgmj1AbIAU
         RxTA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=5zrp/PzfazqQggzhLWFyZwcgzWIAXgRKv6jcYI2cpWA=;
        b=oBzG7KVazaMMiacZLITg7G4DnpoQRLYc4jVVIo2BZubxXnU2wrYaS4DSzQktICV2AN
         0mS9rafhtrPl7W40yVIoCLTztaYemqDpzir74G+2IWCKLXWLt3fOs+l5Ehpeu3B6aFH3
         VTP7oyxYiuRXHIKS9hLvHU9DQoLHdZ7KRKEmZCfqHzi1B5tgRYeS0d2bds9axeYY36Dp
         Z3+Qvv0t/k3Uew1ChdgZW16AXlIEJEkxxLrlGA0Q5ds3OidBX6x04ijQEJOBFYdWisSW
         Az5p6BvepoBiB7kPlpPZv3z5O3hMV8/WLgxgvGF4nSzBrbSqAiyj54wqn6yRQ7DD+TMS
         ig5w==
X-Gm-Message-State: AA+aEWat1uXGlc6mXez6mMIINuxDZxWRyCBCuLb9uJM92Le3cP8B+C7m
	XQbeJOoPO309V/qRSiuyLpYz0Q==
X-Google-Smtp-Source: AFSGD/UHosFhNmPKc5C6up9F9XE9cYrsLJIW8mKClzxZXVWP6oTyuZd5wFn2Eu9w53UTpY+lrjJ6xQ==
X-Received: by 2002:a25:ed5:: with SMTP id 204-v6mr7523195ybo.66.1543767956338;
        Sun, 02 Dec 2018 08:25:56 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a25:ab26:: with SMTP id u35-v6ls5188258ybi.10.gmail; Sun, 02
 Dec 2018 08:25:54 -0800 (PST)
X-Received: by 2002:a25:afcd:: with SMTP id d13-v6mr130791ybj.2.1543767954760;
        Sun, 02 Dec 2018 08:25:54 -0800 (PST)
In-Reply-To: <73866d3d-1466-3bca-55d2-3c00c16127a4@wanadoo.fr>
X-Original-Sender: cppljevans@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: 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:41196
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/41196>

------=_Part_3805_1739465788.1543767953717
Content-Type: multipart/alternative; 
	boundary="----=_Part_3806_1597953238.1543767953717"

------=_Part_3806_1597953238.1543767953717
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable



On Sunday, December 2, 2018 at 7:47:40 AM UTC-6, Vicente J. Botet Escriba=
=20
wrote:
>
> Le 02/12/2018 =C3=A0 02:49, phili...@gmail.com <javascript:> a =C3=A9crit=
 :
>
> Hi all,=20
>
> I have updated the proposal=20
> <https://github.com/ginsbach/CppProposal/blob/release_70/ExtendedScopedEn=
umerations.pdf> to=20
> reflect some of your feedback:
>
> I've some trouble with the way you use sub-typing "there is a natural=20
> correspondence between sub-typing and adding enumerators to enums".=20
>
> I was expecting to have an enum and be able to define sub-types of this=
=20
> enums, by restricting the possible enumerators, not by adding new ones (a=
s=20
> ADA does - see=20
> http://www.adaic.org/resources/add_content/standards/05rm/html/RM-3-5-1.h=
tml).=20
> Have you considered this possibility? Are you sure that the common case i=
s=20
> to extend enumerators, or to restrict them. Maybe both are useful.
> So, for me you are proposing super-types of enums, not sub-types. It is=
=20
> weird that we are using the same syntax as inheritance while we are=20
> defining the opposite relation, but this is already incoherent with the=
=20
> C++11 scoped enum syntax.=20
>
[snip]=20
I agree with Vincente that super-type is the correct term.
The reason it seems weird is because class inheritance is
for product types whereas enum inheritance is for sum types
(e.g. std::variant):

  https://en.wikipedia.org/wiki/Algebraic_data_type

and the duality property of category theory:

  https://en.wikipedia.org/wiki/Dual_(category_theory)
 =20
says that the arrows are reversed in the dual category.
In this particular case, the arrow is the Liskov=20
substitution principle mentioned in Bernardo's post.

More formally, let:

  A <: B
 =20
mean a type A can be substituted where a type B is expected(
i.e. the Liskov principle).

Now if:

  struct sB{int b_1; char b_2;}
  struct sA : sB{ bool a_3};
 =20
then:

  sA <: sB
 =20
IOW, an instance of sA can substituted anywhere an instance
of sB is expected (because sA has all of the fields that sB
has).
 =20
OTOH, if:

  enum eB{b_1,b_2};
  enum eA : eB{a_3};
 =20
then:

  eB <: eA

IOW, an instance of eB (e.g. b_2) can be substituted
anywhere an instance of eA is expected (because b_2 is
actually a member of eA as well as a member of eB).

OTOH, there's an interesting corner case:

  enum eB{};
  enum eA : eB{a_3};
 =20
Now what happens when:

  eB b_0;
 =20
is used where an eA is expected?

I don't know, but I'd guess there would be a core dump or
something as unpleasant.

-regards,
Larry

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/7ab7b56f-e805-4703-a566-d805d08e20e2%40isocpp.or=
g.

------=_Part_3806_1597953238.1543767953717
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Sunday, December 2, 2018 at 7:47:40 AM UTC-6, V=
icente J. Botet Escriba wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
 =20
   =20
 =20
  <div text=3D"#000000" bgcolor=3D"#FFFFFF">
    <div>Le 02/12/2018 =C3=A0 02:49, <a href=3D"javascript:" target=3D"_bla=
nk" gdf-obfuscated-mailto=3D"zJYTvNQjAwAJ" rel=3D"nofollow" onmousedown=3D"=
this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.href=3D&#39=
;javascript:&#39;;return true;">phili...@gmail.com</a> a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote type=3D"cite">
     =20
      <div dir=3D"ltr">Hi all,
        <div><br>
        </div>
        <div>I have updated the <a href=3D"https://github.com/ginsbach/CppP=
roposal/blob/release_70/ExtendedScopedEnumerations.pdf" target=3D"_blank" r=
el=3D"nofollow" onmousedown=3D"this.href=3D&#39;https://www.google.com/url?=
q\x3dhttps%3A%2F%2Fgithub.com%2Fginsbach%2FCppProposal%2Fblob%2Frelease_70%=
2FExtendedScopedEnumerations.pdf\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE_=
f5CeZNAHeg_IuZwkV18F1aX8YA&#39;;return true;" onclick=3D"this.href=3D&#39;h=
ttps://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fginsbach%2FCppPro=
posal%2Fblob%2Frelease_70%2FExtendedScopedEnumerations.pdf\x26sa\x3dD\x26sn=
tz\x3d1\x26usg\x3dAFQjCNE_f5CeZNAHeg_IuZwkV18F1aX8YA&#39;;return true;">pro=
posal</a>=C2=A0to reflect some of your
          feedback:</div>
        <br>
      </div>
    </blockquote>
    <p>I&#39;ve some trouble with the way you use sub-typing &quot;there is=
 a
      natural correspondence between sub-typing and adding enumerators
      to enums&quot;. <br>
    </p>
    <p>I was expecting to have an enum and be able to define sub-types
      of this enums, by restricting the possible enumerators, not by
      adding new ones (as ADA does - see
      <a href=3D"http://www.adaic.org/resources/add_content/standards/05rm/=
html/RM-3-5-1.html" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.=
href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.adaic.org%2Fres=
ources%2Fadd_content%2Fstandards%2F05rm%2Fhtml%2FRM-3-5-1.html\x26sa\x3dD\x=
26sntz\x3d1\x26usg\x3dAFQjCNGXgIm3DKkm2_D1VAgEQTCE7jjjzg&#39;;return true;"=
 onclick=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fww=
w.adaic.org%2Fresources%2Fadd_content%2Fstandards%2F05rm%2Fhtml%2FRM-3-5-1.=
html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGXgIm3DKkm2_D1VAgEQTCE7jjjzg&#=
39;;return true;">http://www.adaic.org/<wbr>resources/add_content/<wbr>stan=
dards/05rm/html/RM-3-5-1.<wbr>html</a>).
      Have you considered this possibility? Are you sure that the common
      case is to extend enumerators, or to restrict them. Maybe both are
      useful.<br>
    </p>
    So, for me you are proposing super-types of enums, not sub-types. It
    is weird that we are using the same syntax as inheritance while we
    are defining the opposite relation, but this is already incoherent
    with the C++11 scoped enum syntax.
    </div></blockquote><div>[snip]=C2=A0</div><div>I agree with Vincente th=
at super-type is the correct term.<br>The reason it seems weird is because =
class inheritance is<br>for product types whereas enum inheritance is for s=
um types<br>(e.g. std::variant):<br><br>=C2=A0 https://en.wikipedia.org/wik=
i/Algebraic_data_type<br><br>and the duality property of category theory:<b=
r><br>=C2=A0 https://en.wikipedia.org/wiki/Dual_(category_theory)<br>=C2=A0=
 <br>says that the arrows are reversed in the dual category.<br>In this par=
ticular case, the arrow is the Liskov <br>substitution principle mentioned =
in Bernardo&#39;s post.<br><br>More formally, let:<br><br>=C2=A0 A &lt;: B<=
br>=C2=A0 <br>mean a type A can be substituted where a type B is expected(<=
br>i.e. the Liskov principle).<br><br>Now if:<br><br>=C2=A0 struct sB{int b=
_1; char b_2;}<br>=C2=A0 struct sA : sB{ bool a_3};<br>=C2=A0 <br>then:<br>=
<br>=C2=A0 sA &lt;: sB<br>=C2=A0 <br>IOW, an instance of sA can substituted=
 anywhere an instance<br>of sB is expected (because sA has all of the field=
s that sB<br>has).<br>=C2=A0 <br>OTOH, if:<br><br>=C2=A0 enum eB{b_1,b_2};<=
br>=C2=A0 enum eA : eB{a_3};<br>=C2=A0 <br>then:<br><br>=C2=A0 eB &lt;: eA<=
br><br>IOW, an instance of eB (e.g. b_2) can be substituted<br>anywhere an =
instance of eA is expected (because b_2 is<br>actually a member of eA as we=
ll as a member of eB).<br><br>OTOH, there&#39;s an interesting corner case:=
<br><br>=C2=A0 enum eB{};<br>=C2=A0 enum eA : eB{a_3};<br>=C2=A0 <br>Now wh=
at happens when:<br><br>=C2=A0 eB b_0;<br>=C2=A0 <br>is used where an eA is=
 expected?<br><br>I don&#39;t know, but I&#39;d guess there would be a core=
 dump or<br>something as unpleasant.<br><br>-regards,<br>Larry<br><br></div=
></div>

<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/7ab7b56f-e805-4703-a566-d805d08e20e2%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7ab7b56f-e805-4703-a566-d805d08e20e2=
%40isocpp.org</a>.<br />

------=_Part_3806_1597953238.1543767953717--

------=_Part_3805_1739465788.1543767953717--

.
