Re: Extended 'Succ attribute?
- From: "Adam Beneschan" <adam@xxxxxxxxxx>
- Date: 22 Nov 2006 18:04:37 -0800
Jérémie Lumbroso wrote:
Hello,
I just started Ada and was wondering if there is a way to make the Succ
attribute of discrete types behave in a cyclic manner (akin to the
modular type):
type T_DAY is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
...
day := T_DAY'(Sun);
day := T_DAY'Succ(day); -- that this returns 'Mon' instead of
-- a type constraint error
I could of course define my own function to do this, but I wish to know
if there is a way to get Ada to do it itself.
No.
The best you could do would be to declare a modular type, and then
declare Mon, Tue, etc. as constants of that type:
type T_DAY is mod 7;
Mon : constant T_DAY := 0;
Tue : constant T_DAY := 1;
etc.
Then T_DAY'Succ(X) will wrap around. But I don't see any advantage to
doing things this way. I'd
just make it an enumeration literal and define your own Succ function.
-- Adam
.
- Follow-Ups:
- Re: Extended 'Succ attribute?
- From: Peter Hermann
- Re: Extended 'Succ attribute?
- References:
- Extended 'Succ attribute?
- From: Jérémie Lumbroso
- Extended 'Succ attribute?
- Prev by Date: Extended 'Succ attribute?
- Next by Date: Re: I/O streaming with custom data transport
- Previous by thread: Extended 'Succ attribute?
- Next by thread: Re: Extended 'Succ attribute?
- Index(es):
Relevant Pages
|