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


Groups > comp.lang.c++ > #13689

Re: one enum is a subset of another

From Thomas Boell <tboell@domain.invalid>
Newsgroups comp.lang.c++
Subject Re: one enum is a subset of another
Date 2012-02-01 14:08 +0100
Organization albasani.net
Message-ID <20120201140814.3c116fb2@arcadia> (permalink)
References <7aac0ea8-61ab-481e-80a6-c9ab215b009e@gi10g2000vbb.googlegroups.com>

Show all headers | View raw


On Tue, 31 Jan 2012 14:56:03 -0800 (PST)
Christopher <cpisz@austin.rr.com> wrote:

> A developer before me created a large enumeration we can call
> EnumType1.
> He then, right under it, typedef-ed another
> 
> typedef EnumType1 EnumType2
> 
> He then created a comment "alias, should only include x types", where
> x is a rule defining a subset of EnumType1
> 
> This is crap imo. Any function or method declared to take EnumType2,
> would happily take a value from  EnumType1 that does not meet the x
> criteria.
> 
> Since I know the subset from EmunType1 that meets the x criteria, how
> can I define a subset EnumType2 that only includes those enums without
> typing the whole darn subset twice?
> 
> Example
> enum Fruit
> {
>    APPLE = 0,
>    BANANA,
>    ORANGE,
>    TANGERINE,
>    GRAPEFRUIT,
>    NUM_FRUITS
> };
> 
> typedef Fruit Citrus;   // This is crap and I want to fix it

You could do something like this:

#define FRUIT_VALUES	\
    APPLE,	\
    BANANA,	\
    ORANGE

enum Fruit
{
	FRUIT_VALUES
};

enum Things
{
	FRUIT_VALUES,
	BEERCAN, CAR, ALOT
};

Whether using the preprocessor like this is "good style" depends on
your point of view.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

one enum is a subset of another Christopher <cpisz@austin.rr.com> - 2012-01-31 14:56 -0800
  Re: one enum is a subset of another Paul N <gw7rib@aol.com> - 2012-01-31 15:19 -0800
    Re: one enum is a subset of another Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-31 23:56 +0000
  Re: one enum is a subset of another Marcel Müller <news.5.maazl@spamgourmet.com> - 2012-02-01 09:51 +0100
    Re: one enum is a subset of another Larry Evans <cppljevans@suddenlink.net> - 2012-02-01 11:46 -0600
      Re: one enum is a subset of another Marcel Müller <news.5.maazl@spamgourmet.com> - 2012-02-01 21:14 +0100
  Re: one enum is a subset of another Thomas Boell <tboell@domain.invalid> - 2012-02-01 14:08 +0100
    Re: one enum is a subset of another Tobias Müller <troplin@bluewin.ch> - 2012-02-01 21:34 +0000
    Re: one enum is a subset of another "Matt D." <nospam@invalid.local> - 2012-02-02 00:37 +0100
      Re: one enum is a subset of another Thomas Boell <tboell@domain.invalid> - 2012-02-02 02:38 +0100
  Re: one enum is a subset of another Larry Evans <cppljevans@suddenlink.net> - 2012-02-01 12:28 -0600

csiph-web