Article View: comp.std.c++
Article #2332Range types? (was Re: Inheriting Enums)
From: Dr. Richard Botting
Date: Fri, 27 Oct 1995 22:30
Date: Fri, 27 Oct 1995 22:30
44 lines
1750 bytes
1750 bytes
Steve Clamage (clamage@Eng.Sun.COM) wrote on the old topic):
: For example:
: class chili {
: public:
: enum hotness { low=0, medium=500, high=1000, scary=10000 };
: };
So, a declaration like
enum range{first=1, last=20};
permits
for( range i=first; i<=last; i++)
whatever;
An hence... (forgive my ignorance below):
template <int first, int last> class range{
enum{ FIRST=first, LAST=last }v;
public:
range(){v=FIRST;}
range val(){return v}
void reset(){v=FIRST;}
bool ok(){return FIRST<=v && v<=LAST;}
range& operator++{ v++; return *this;}
...
}
for(range<0,17> i; ok(i); i++)
for(range<0,32>chn; ok(chn); chn++)
{ char c=char(chn);
whatever...
}
--
dick@csci.csusb.edu=rbotting@wiley.csusb.edu.
Find out what's new at http://www.csci.csusb.edu/doc/www.sites.html
Disclaimer:`CSUSB may or may not agree with this message`.
Copyright(1995):Copy this freely but include the following link to the
<a href="http://www.csci.csusb.edu/dick/signature.html">author's signature</a>
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<46o780$2au@news.csus.edu>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<199510181645.MAA13614@atlanta.com> <463i2e$p22@engnews2.Eng.Sun.COM>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: dick@silicon.csci.csusb.edu (Dr. Richard Botting) Newsgroups: comp.std.c++ Subject: Range types? (was Re: Inheriting Enums) Date: 27 Oct 1995 22:30:45 GMT Organization: CS Dept., Calif. State Univ., San Bernardino Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <46o780$2au@news.csus.edu> References: <199510181645.MAA13614@atlanta.com> <463i2e$p22@engnews2.Eng.Sun.COM> NNTP-Posting-Host: physics2.berkeley.edu