comp.lang.ada
 help / color / mirror / Atom feed
From: Petter <petter_fryklund@hotmail.com>
Subject: Re: (Num_Types.Mod_4 range 1..8) ------->why not (1..8)?
Date: Tue, 19 May 2009 00:47:03 -0700 (PDT)
Date: 2009-05-19T00:47:03-07:00	[thread overview]
Message-ID: <201fbf41-65ed-4428-b814-ea0c4065e10e@v17g2000vbb.googlegroups.com> (raw)
In-Reply-To: ee738ee7-3579-4eb2-8894-6a55708b34dd@h23g2000vbc.googlegroups.com

For scalar types Checked_Conversion is a good idea:

generic
   type Source is (<>);
   type Target is (<>);

function Checked_Conversion (S : Source) return Target;

with Ada.Unchecked_Conversion;
function Checked_Conversion (S : Source) return Target is
   function "+" is new Ada.Unchecked_Conversion (Source => Source,
                                                 Target => Target);
begin
   declare
      Return_Value : Target := + S;
   begin
      if not Return_Value'Valid then
         raise Constraint_Error;
      end if;
      return Return_Value;
   end;
end Checked_Conversion;



  reply	other threads:[~2009-05-19  7:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 19:19 (Num_Types.Mod_4 range 1..8) ------->why not (1..8)? convergence82
2009-05-18 19:36 ` Georg Bauhaus
2009-05-18 19:58   ` convergence82
2009-05-18 20:50     ` Adam Beneschan
2009-05-18 20:53     ` Georg Bauhaus
2009-05-18 21:12       ` convergence82
2009-05-18 21:24       ` Adam Beneschan
2009-05-19  6:26         ` christoph.grein
2009-05-19  7:47           ` Petter [this message]
2009-05-19  8:04             ` christoph.grein
2009-05-19 13:13               ` Petter
2009-05-19 15:27                 ` Georg Bauhaus
2009-05-19 17:53           ` Adam Beneschan
2009-05-18 19:49 ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox