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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f30ef262af690ce0 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: numbers as 'generics' parameters Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <482dd91a$1_3@news.bluewin.ch> Date: Sat, 17 May 2008 09:47:46 +0200 Message-ID: <1g4p2jgvi3k8j.1j2xk6p9ws3a2.dlg@40tude.net> NNTP-Posting-Date: 17 May 2008 09:47:45 CEST NNTP-Posting-Host: 3a6f9c29.newsspool1.arcor-online.net X-Trace: DXC=UNI?oEic==]BZ:afN4Fo<]lROoRA<`=YMgDjhgBbjgW5j\LYKG[6LHn;2LCVN[ On Fri, 16 May 2008 13:52:23 -0700 (PDT), Maciej Sobczak wrote: > On 16 Maj, 20:57, Gautier wrote: > >> generic >> N: Integer; >> package Fixed_size_vectors is >> Vector: array(1..N) of Float; > > I guess: > type Vector is array (1..N) of Float; > >> end; > > How to write an operation that ensures *at compile time* that its two > parameters are Fixed_size_vectors of equal N? > Declare it in a child package? Is there any other option? The first step is a bit tedious, but it is advisable to "rename" all formal generic parameters within the package specification. [I don't know why aren't they visible. That was a language design decision]. Anyway, here you go: generic N : Integer; package Fixed_Size_Vector is Size : Integer renames N; type Vector is array (1..N) of Float; end Fixed_Size_Vector; package V1 is new Fixed_Size_Vector (25); package V2 is new Fixed_Size_Vector (V1.Size); > Similar question can be asked for (un)constrained and discriminated > types. What are the options for such an operation? You do it declaring a subtype, that constraints the discriminant or bounds. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de