comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: array conversion - how to do?
Date: 1997/06/30
Date: 1997-06-30T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.97Jun30174911@spectre.mitre.org> (raw)
In-Reply-To: 5p3rad$8n8$1@gonzo.sun3.iaf.nl


In article <5p3rad$8n8$1@gonzo.sun3.iaf.nl> Geert Bosch <geert@gonzo.sun3.iaf.nl> writes:

  > The drawback of my generic Array_Conversion is that it is too powerful
  > in that it can convert an array of A to an array of B as long as B is
  > a new A. I would like to only allow conversion when A and B are subtype
  > compatible. Anyway, the point was to avoid copying as happens in the
  > loop approach, but at least GNAT doesn't seem to do that yet.

   One of those nasty "depend upon the compiler to do the right thing"
tricks you can use is to provide your own generic Checked_Conversion
routine which either does the run-time check OR just calls
Unchecked_Conversion if the source subrange is a subset of the target
subrange.  Even if the compiler is pretty dumb, you will at least get
a relatively quick check in the case where no check is required.  But
if the subranges are static and the compiler optimizes such generics
correctly (a pragma Inline can't hurt) the if statement will get
optimized away.

   A really fancy trick, and probably not worth the effort.  If the
ranges are nesting, you probably have more knowledge on the subject
than the compiler.



--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




      reply	other threads:[~1997-06-30  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-24  0:00 array conversion - how to do? Geert Bosch
1997-06-27  0:00 ` Wes Groleau
1997-06-27  0:00   ` Robert Dewar
1997-06-28  0:00     ` Geert Bosch
1997-07-03  0:00       ` Robert Dewar
1997-07-04  0:00         ` Geert Bosch
1997-07-04  0:00         ` Geert Bosch
1997-07-04  0:00           ` Robert Dewar
1997-06-28  0:00 ` Robert I. Eachus
1997-06-28  0:00   ` Geert Bosch
1997-06-30  0:00     ` Robert I. Eachus [this message]
replies disabled

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