Topic: enum for ranges?
Author: The Great God MYSH <B.V.Pflanz@ncl.ac.uk>
Date: 27 Nov 1994 17:18:31 GMT Raw View
Is it possible, to define an enum type, which comprises of a range
of another type, as it is in Pascal with (for example) 1..60 ?
If this is not possible, then why not ? Shouldn't this be a part of
C++? After all, it makes sense for the representation of things such
as seconds, minutes, etc.
Just a thought...
mysh
--
+---------------------------------------------------------------+
| Benjamin Pflanz | AKA: The Great God MYSH |
| B.V.Pflanz@ncl.ac.uk | Elymas |
| Uni of Newcastle upon Tyne | Streak |
| Dept. of Computing Science | |
|---------------------------------------------------------------|
| "Behind the illusion of reality are forces that speak to me" |
| - Jaz Coleman (of Killing Joke) |
+---------------------------------------------------------------+
Author: mhh@b4pph108.rus.uni-stuttgart.de (Mark Hollomon)
Date: 28 Nov 1994 18:33:35 GMT Raw View
In article <3baf17$rcn@whitbeck.ncl.ac.uk>,
The Great God MYSH <B.V.Pflanz@ncl.ac.uk> wrote:
>
>Is it possible, to define an enum type, which comprises of a range
>of another type, as it is in Pascal with (for example) 1..60 ?
>If this is not possible, then why not ? Shouldn't this be a part of
>C++? After all, it makes sense for the representation of things such
>as seconds, minutes, etc.
>
>Just a thought...
>mysh
>
How 'bout :
template <int min, int max> class RangeInt {
// various constructors,etc that check min and max and throw an
// exception
}
typedef RangeInt<0,59> Seconds;
---
Mark Hollomon
hollomon@cybernetics.net
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 29 Nov 1994 17:09:11 GMT Raw View
In article rcn@whitbeck.ncl.ac.uk, The Great God MYSH <B.V.Pflanz@ncl.ac.uk> writes:
>
>Is it possible, to define an enum type, which comprises of a range
>of another type, as it is in Pascal with (for example) 1..60 ?
>If this is not possible, then why not ? Shouldn't this be a part of
>C++? After all, it makes sense for the representation of things such
>as seconds, minutes, etc.
C++ has no built-in subrange types as in Pascal. You can define your
own (subrange) numeric classes if you wish. There is no ".." syntax
to indicate a range, even if you define your own class.
Subrange types is one of many nice features. Not every nice feature of every
language can be included in C++. See "The Design and Evolution of C++" for
more on this topic.
---
Steve Clamage, stephen.clamage@eng.sun.com