From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8bf89a9bbd99a65e X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: array conversion - how to do? Date: 1997/06/30 Message-ID: #1/1 X-Deja-AN: 253701672 References: <5opej8$rv5$1@gonzo.sun3.iaf.nl> <5p3rad$8n8$1@gonzo.sun3.iaf.nl> Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.ada Date: 1997-06-30T00:00:00+00:00 List-Id: In article <5p3rad$8n8$1@gonzo.sun3.iaf.nl> Geert Bosch 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...