Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #257

Re: New strongly type enum proposal featuring inherited enums

Message-ID <j352gi$7n1$1@localhost.localdomain> (permalink)
Newsgroups comp.std.c++
From Bart van Ingen Schenau<bart@ingen.ddns.info>
Subject Re: New strongly type enum proposal featuring inherited enums
Organization No organisation in particular
References <4e49ea26$2@news.x-privat.org> <j2inpn$aa2$1@dont-email.me> <j33rkg$qrl$1@dont-email.me>
Date 2011-08-25 20:51 -0600

Show all headers | View raw


Daniel Krügler<daniel.kruegler@googlemail.com>  Wrote:

>  Am 24.08.2011 23:06, schrieb Phil Bouchard:
>  >   On 8/18/2011 9:54 AM, Daniel Krügler wrote:
>  >>
>  >>>   2) Inheriting from another enum would be quite useful. For
>  example:
>  >>>   enum class Widget {button, combobox, listview};
>  >>>   enum class SuperWidget : Widget {iconview}
>  >>
>  >>   The current state would not disallow such an extension in the
>  future,
>  >>   so what is the problem?
>  >
>  >   I don't think it'll be a good idea to make the two coexist
>  together:
>  >   enum class SuperWidget : Widget {iconview} // derived
>  >   enum class SuperWidget : unsigned int {iconview} // subtyping
>
>  I'm missing the rationale for your dislike. Widget is still a type that
>  has an integral type as underlying type, so what is the drastic
>  difference, if you extend scoped enums to allow for extending
>  another enum? We have no enumeration values in integral types, so
>  we have we don't have an observable difference. If you want to
>  define that SuperWidget contains the enumeration values of
>  Widget, this is simply a definition problem.

The dislike probably comes from how an enum is typically viewed.
To my knowledge, an enum is typically viewed as an integer with a limited
set of possible values (that some/most of those values also have a symbolic
name is incidental). A scoped enum gives you the added value of being able
to specify the underlying storage.

With this view the interpretation of the declarations would be:
  enum class Widget : unsigned int { list_view, box, button }; /* RESTRICT a
storage cell of size unsigned int to store only the specified values */
  enum class SuperWidget : Widget { iconview }; /* EXTEND? the allowed values
to include iconview */

OTOH, you seem to view a (scoped) enum as its base-type with some of the
values given a symbolic name:

  enum class Widget : unsigned int { list_view, box, button }; /* Can store
all values of an unsigned int, with three of them given a specific,
symbolic, name */
  enum class SuperWidget : Widget { iconview }; /* Extend the list of
symbolic names to include iconview */

>
>  Greetings from Bremen,
>
>  - Daniel Krügler

Bart v Ingen Schenau


-- 
[ comp.std.c++ is moderated.  To submit articles, try posting with your ]
[ newsreader.  If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

New strongly type enum proposal featuring inherited enums Phil Bouchard <philippe@fornux.com> - 2011-08-16 21:28 -0600
  Re: New strongly type enum proposal featuring inherited enums Daniel Krügler <daniel.kruegler@googlemail.com> - 2011-08-18 07:54 -0600
    Re: New strongly type enum proposal featuring inherited enums Phil Bouchard<philippe@fornux.com> - 2011-08-24 14:06 -0700
      Re: New strongly type enum proposal featuring inherited enums Daniel Krügler<daniel.kruegler@googlemail.com> - 2011-08-24 17:39 -0700
        Re: New strongly type enum proposal featuring inherited enums Bart van Ingen Schenau<bart@ingen.ddns.info> - 2011-08-25 20:51 -0600
          Re: New strongly type enum proposal featuring inherited enums =3D?ISO-8859-15?Q?Daniel_Kr=3DFCgler?=3D <daniel.kruegler@googlemail.= com> - 2011-09-07 11:08 -0700
            Re: New strongly type enum proposal featuring inherited enums Miles Bader <miles@gnu.org> - 2011-09-08 14:46 -0700
              Re: New strongly type enum... why not use "using"? "peter miller"<fuchsia.groan@virgin.net> - 2011-09-12 11:18 -0700
                Re: New strongly type enum... why not use "using"? Miles Bader<miles@gnu.org> - 2011-09-13 09:29 -0700
                Re: New strongly type enum... why not use "using"? "peter miller"<fuchsia.groan@virgin.net> - 2011-09-15 14:13 -0700
  Re: New strongly type enum proposal featuring inherited enums Pete Becker <pete@versatilecoding.com> - 2011-08-18 07:51 -0600
    Re: New strongly type enum proposal featuring inherited enums Victor Bazarov<v.bazarov@comcast.invalid> - 2011-08-24 14:06 -0700
    Re: New strongly type enum proposal featuring inherited enums Paavo Helde<myfirstname@osa.pri.ee> - 2011-08-24 14:06 -0700
    Re: New strongly type enum proposal featuring inherited enums Francis Glassborow<francis.glassborow@btinternet.com> - 2011-08-24 14:52 -0700
      Re: New strongly type enum proposal featuring inherited enums Phil Bouchard<philippe@fornux.com> - 2011-08-24 17:39 -0700
  Re: New strongly type enum proposal featuring inherited enums Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-08-18 07:53 -0600
    Re: New strongly type enum proposal featuring inherited enums Phil Bouchard<philippe@fornux.com> - 2011-08-24 14:52 -0700
  Re: New strongly type enum proposal featuring inherited enums Marcel Müller <news.5.maazl@spamgourmet.com> - 2011-08-18 07:52 -0600
    Re: New strongly type enum proposal featuring inherited enums Phil Bouchard<philippe@fornux.com> - 2011-08-23 18:20 -0700
    Re: New strongly type enum proposal featuring inherited enums Phil Bouchard <philippe@fornux.com> - 2011-08-24 14:52 -0700
    Re: New strongly type enum proposal featuring inherited enums Phil Bouchard <philippe@fornux.com> - 2011-08-24 14:52 -0700
  Re: New strongly type enum proposal featuring inherited enums Francis Glassborow<francis.glassborow@btinternet.com> - 2011-08-24 14:06 -0700
  Re: New strongly type enum proposal featuring inherited enums "Bo Persson"<bop@gmb.dk> - 2011-08-24 14:06 -0700
  Re: New strongly type enum proposal featuring inherited enums red floyd<no.spam.here@its.invalid> - 2011-08-24 14:06 -0700
  Re: New strongly type enum proposal featuring inherited enums Seungbeom Kim<musiphil@bawi.org> - 2011-08-24 14:06 -0700
    Re: New strongly type enum proposal featuring inherited enums Phil Bouchard<philippe@fornux.com> - 2011-08-24 17:39 -0700
    Re: New strongly type enum proposal featuring inherited enums Phil Bouchard<philippe@fornux.com> - 2011-08-24 17:40 -0700
    Re: New strongly type enum proposal featuring inherited enums Phil Bouchard<philippe@fornux.com> - 2011-08-24 17:40 -0700

csiph-web