Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #13689
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Thomas Boell <tboell@domain.invalid> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: one enum is a subset of another |
| Date | Wed, 1 Feb 2012 14:08:14 +0100 |
| Organization | albasani.net |
| Lines | 55 |
| Message-ID | <20120201140814.3c116fb2@arcadia> (permalink) |
| References | <7aac0ea8-61ab-481e-80a6-c9ab215b009e@gi10g2000vbb.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.albasani.net IanmFi5fqodd8cr+B2q+zRqFOp0erJ3kAbeRWSxb4xDzv4T3dB1usN5qugq6/++qmX5+tv6qjB5x68M7leBrTjy+aZn1yeQd3t1x0uhS0jyl8DDFnUrzAyaDTKDw39V2 |
| NNTP-Posting-Date | Wed, 1 Feb 2012 13:08:14 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="7kGue1uLYIVV9zDiRcwGS9yQpfKOfq7XpXoh8SgyJJKaXZ8AMY4IC4qHymLaP7tR5D8x8f2klICTpbain/PeleF2pgjPc6bSXA7LATmhSeyrU940QCuFdiDyupoOFYLd"; mail-complaints-to="abuse@albasani.net" |
| X-Newsreader | Claws Mail 3.7.8 (GTK+ 2.24.4; i686-pc-linux-gnu) |
| Cancel-Lock | sha1:mr+3uTWIwphT3j27mFBjovCnDsg= |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c++:13689 |
Show key headers only | 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
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