comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <pchapin@sover.net>
Subject: Re: numbers as 'generics' parameters
Date: Fri, 16 May 2008 19:09:52 -0400
Date: 2008-05-16T19:09:52-04:00	[thread overview]
Message-ID: <482e143e$0$11203$4d3efbfe@news.sover.net> (raw)
In-Reply-To: <c2595e25-a6e3-47ef-8523-dcd946a2a635@p25g2000hsf.googlegroups.com>

Maciej Sobczak wrote:

> On 16 Maj, 20:57, Gautier <gaut...@fakeaddress.nil> 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?

I may not understand the question, but isn't this trivial?

procedure Check is
    package Short_Vectors is new Fixed_Size_Vectors(N => 3);
    package Long_Vectors is new Fixed_Size_Vectors(N => 6);

    V1     : Short_Vectors.Vector;
    V2, V3 : Long_Vectors.Vector;
begin
    V3 := V1 + V2;
end Check;

Assuming an appropriate overload for "+" this produces a compile time 
error for me.

Peter



  reply	other threads:[~2008-05-16 23:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-16 17:26 numbers as 'generics' parameters jhc0033
2008-05-16 17:55 ` Adam Beneschan
2008-05-16 19:12   ` John B. Matthews
2008-05-16 18:34 ` jimmaureenrogers
2008-05-16 18:57 ` Gautier
2008-05-16 20:52   ` Maciej Sobczak
2008-05-16 23:09     ` Peter C. Chapin [this message]
2008-05-17  7:47     ` Dmitry A. Kazakov
2008-05-17 16:29       ` Maciej Sobczak
2008-05-17 17:34         ` Dmitry A. Kazakov
2008-05-18 13:58           ` Maciej Sobczak
2008-05-18 14:52             ` Dmitry A. Kazakov
2008-05-18 20:37               ` Maciej Sobczak
2008-05-19  9:02                 ` Dmitry A. Kazakov
2008-05-19  5:16             ` Ivan Levashew
2008-05-19  8:26               ` Maciej Sobczak
2008-05-16 20:22 ` Jeffrey R. Carter
2008-05-21 15:32   ` 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