Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Miles Bader Newsgroups: comp.std.c++ Subject: Re: New strongly type enum proposal featuring inherited enums Date: Thu, 8 Sep 2011 14:46:01 -0700 (PDT) Organization: NEC Electronics Lines: 50 Sender: std-cpp-request@vandevoorde.com Approved: james.dennett@gmail.com Message-ID: References: <4e49ea26$2@news.x-privat.org> Content-Type: text/plain X-Trace: news.albasani.net jzyrXqCe61UoNlIyfznyUTm7uy0D15PSx+7Q8qbn9YWYnC7TLrW0p5VtGMtrNr+L5IFdwrHbdTF3pSqeCkHiFQ== NNTP-Posting-Date: Thu, 8 Sep 2011 21:46:03 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="XJsyUAJt7QZ9SP7xnUxrx2PbOjkyV8NeNmVKFF0reNYbQFIs9RAxb/7h+calMvMiJqsjG5gEV4UgGav5pd6BTHyw00bTpvcKTRiT6I6ZTBVPfG6ECGmivRWduqJ4pajw"; mail-complaints-to="abuse@albasani.net" X-Mailer: Perl5 Mail::Internet v2.05 X-Submission-Address: std-cpp-submit@vandevoorde.com Cancel-Lock: sha1:WqWCaMhxbWWK2XdPjjjkhfecSIA= X-Original-Date: Thu, 08 Sep 2011 15:00:30 +0900 Xref: x330-a1.tempe.blueboxinc.net comp.std.c++:280 =?ISO-8859-15?Q?Daniel_Kr=FCgler?= writes: > > enum class Widget : unsigned int { list_view, box, button }; > > enum class SuperWidget : Widget { iconview }; > > I don't know yet, what the meaning should be. For me one intuitive > interpretation would be that SuperWidget has two enumerators of value 0. > An alternative interpretation could be that SuperWidget::iconview has > the numeric value 3 in this example. Surely the latter... That sort of usage seems very common in existing code, by doing something like: enum X { a, b, X_MAX }; enum Y { d = X_MAX + 1, e, Y_MAX }; Real inheritance seems like a natural way to sugar this up a bit. Some other possible behavior: * when the compiler does type checking of enum classes, consider enum classes related by inheritance compatible in some appropriate sense (e.g., an enum superclass can be assigned to an enum subclass, enum classes related by inheritance can be compared, etc) * for enum classes, import all the members of the parent into the child, e.g.: enum class X : whatever { a, b }; enum class Y : X { d, e }; would yield X::a = 0, X::b = 1, Y::a = 0, Y::b = 1, Y::d = 2, Y::e = 3. [dunno about this one; maybe it's not desirable...] -Miles -- `...the Soviet Union was sliding in to an economic collapse so comprehensive that in the end its factories produced not goods but bads: finished products less valuable than the raw materials they were made from.' [The Economist] [ 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 ]