From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: numbers as 'generics' parameters
Date: Sun, 18 May 2008 13:37:47 -0700 (PDT)
Date: 2008-05-18T13:37:47-07:00 [thread overview]
Message-ID: <0ebf73b9-4c38-4279-99de-da230e978c83@k37g2000hsf.googlegroups.com> (raw)
In-Reply-To: 1nng3xn67do3n$.1f4isrrr1y1m2.dlg@40tude.net
On 18 Maj, 16:52, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
wrote:
> generic
> N : Natural;
> package Strings_Nobody_Ever_Needed is
> type Pascal_String is new String (1..N);
> procedure Foo (L, R : Pascal_String);
> end Strings_Nobody_Ever_Needed;
No. The package is already written and no code can be added.
A child package would do, perhaps?
Note also that the constraint to have equal strings is only an example
and probably does not show the full problem.
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);
and it would ensure *at compile time* that the second string is twice
as long as the first one. It should be obvious now that such a
constraint can be anything that is computable (at compile time).
What about this?
(again: the package in question is read only)
> 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?
> 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.
--
Maciej Sobczak * www.msobczak.com * www.inspirel.com
next prev parent reply other threads:[~2008-05-18 20:37 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 [this message]
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