From -5924888933798003702
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,c0549fe0e994892d
X-Google-Attributes: gidf78e5,public
From: horstman@sjsumcs.sjsu.edu (Cay Horstmann)
Subject: Re: Enums
Date: 1995/04/16
Message-ID: <3mrac7$gmm@jupiter.SJSU.EDU>#1/1
X-Deja-AN: 101010188
references: <3mln9i$mp4@news1.halcyon.com> <3mm6pm$53n@fsgm01.fnal.gov>
organization: San Jose State University - Math/CS Dept
newsgroups: comp.std.c++

David Sachs (b91926@fsgm01.fnal.gov) wrote:
: gadget@coho.halcyon.com (Timothy Sharpe) writes:

: >Consider:
: >enum day 
: >{monday, tuesday, wednesday, thursday, friday};

: >This is interesting in a switch statement:
: >switch(dayCurrent) { case monday: ... }

: >But is uninteresting as an integer:
: >dayCurrent++

: >Has someone designed an enum which wraps around (friday+1 = monday) ?

: A post-ARM addition to the standard allows operators to be overloaded
: for enum types, so you can define the functions:

: day operator++(day&,int);   // postincrement form
: day& operator++(day&);      // preincrement form

: which do what you want.

I am not sure that is a good thing to do, though. It conflicts with
the more desirable goal of having an STL style iteration protocol:

enum Weekday { monday, tuesday, ..., friday, end, begin = 0 }

and then iterate over all weekdays:

	for (Weekday w = Weekday::begin; w != Weekday::end; w++)

Cay



