From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: numbers as 'generics' parameters
Date: Mon, 19 May 2008 11:02:27 +0200
Date: 2008-05-19T11:02:27+02:00 [thread overview]
Message-ID: <mwqtukx8u0mj$.ojvnfqw3jxid$.dlg@40tude.net> (raw)
In-Reply-To: 0ebf73b9-4c38-4279-99de-da230e978c83@k37g2000hsf.googlegroups.com
On Sun, 18 May 2008 13:37:47 -0700 (PDT), Maciej Sobczak wrote:
> On 18 Maj, 16:52, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
>
> Note also that the constraint to have equal strings is only an example
> and probably does not show the full problem.
(The problem; I don't understand, BTW)
> I might have written my code like this instead:
>
> template <size_t N>
> void foo(const fixed_size_string<N> & s1,
> const fixed_size_string<2 * N> & s2);
Easily:
generic
N : Natural;
package Silly_String is
type Pascal_String is new String (1..N);
end Silly_String;
with Silly_String;
generic
with package One_Silly is new Silly_String (<>);
with package Twice_As_Silly is
new Silly_String (One_Silly.Pascal_String'Length * 2);
procedure Foo
( S1 : One_Silly.Pascal_String;
S2 : Twice_As_Silly.Pascal_String
);
>> If you replaced the type declaration in Strings_Nobody_Ever_Needed to
>>
>> subtype Pascal_String is String (1..N);
>>
>> you would start to see what's wrong with all this... (:-))
>
> No, I don't follow. Could you please explain?
This Pascal_String would clash when multiple instantiated. The constraint
in your examples is a part of the type. This is wrong. The constraint of
the subtype is a proper constraint. To violate it is *legal*, so in order
to check it statically you need other (finer) means.
>> Talking about strings, they are allowed to have statically unknown length
>
> Yes - the string was only a vehicle to show the problem. It might be a
> matrix of size N or just about anything else.
Still, for a vast majority of them, it is wrong to have the constraint a
part of the type. This is a fundamental issue, why generics are not a
solution.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2008-05-19 9:02 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
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 [this message]
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