From: Tucker Taft <stt@averstar.com>
Subject: Re: non-consecutive ranges
Date: 1999/04/30
Date: 1999-04-30T00:00:00+00:00 [thread overview]
Message-ID: <3729FE8E.4C1B2091@averstar.com> (raw)
In-Reply-To: 7gct90$7hr$1@nnrp1.dejanews.com
vlight@my-dejanews.com wrote:
>
> is there a way to define a variable to have a non-consecutive range? for
> instance, let's say i wanted to define variable X with a range from 2 to 1024
> and 4096 to 8192.
>
> X : Integer range (1 .. 1024) and (4096 .. 8192);
>
> or something similar to this declaration. in addition to define
> non-consecutive ranges, could i define a range of odd numbers? even numbers?
>
> how would i go about declaring this?
There is nothing like this built into the language.
However, you could define a private type and a "convert_from_int"
function which did an arbitrarily complicated test before
agreeing to convert the integer to a value of the private type.
You could "inline" this function to get roughly the same
performance as if the capability were supported directly
through some special syntax.
If you had a general requirement for types like this, you
could go so far as to write a generic package to be used
for defining such "holey" types, with generic formal parameters
indicating the gap(s) in the range. E.g.:
generic
type Underlying_Type is (<>);
First, Gap_First, Gap_Last, Last : Underlying_Type;
package Holey_Types is
type Holey is private;
function Make_Holey(Val : Underlying_Type) return Holey;
function Val(H : Holey) return Underlying_Type;
private
pragma Inline(Make_Holey, Val);
type Holey is new Underlying_Type range First .. Last;
end Holey_Types;
package body Holey_Types is
function Make_Holey(Val : Underlying_Type) return Holey is
begin
if Val in Gap_First .. Gap_Last then
raise Constraint_Error;
end if;
return Holey(Val); -- Constraint_Error if not in First .. Last
end Make_Holey;
function Val(H : Holey) return Underlying_Type is
begin
return Underlying_Type(H);
end Val;
end Holey_Types;
> joe
--
-Tucker Taft stt@averstar.com http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.) Burlington, MA USA
next prev parent reply other threads:[~1999-04-30 0:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-30 0:00 non-consecutive ranges vlight
1999-04-30 0:00 ` Tucker Taft [this message]
1999-04-30 0:00 ` dennison
1999-04-30 0:00 ` dennison
1999-05-01 0:00 ` Robert B. Love
1999-05-04 0:00 ` fraser
1999-05-01 0:00 ` Ehud Lamm
1999-05-01 0:00 ` bglbv
1999-05-02 0:00 ` Ehud Lamm
1999-05-01 0:00 ` Robert Dewar
1999-05-01 0:00 ` dvdeug
1999-05-03 0:00 ` Josh Highley
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox