Re: numbers as 'generics' parameters
- From: "Dmitry A. Kazakov" <mailbox@xxxxxxxxxxxxxxxxx>
- Date: Mon, 19 May 2008 11:02:27 +0200
On Sun, 18 May 2008 13:37:47 -0700 (PDT), Maciej Sobczak wrote:
On 18 Maj, 16:52, "Dmitry A. Kazakov" <mail...@xxxxxxxxxxxxxxxxx>
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
.
- References:
- numbers as 'generics' parameters
- From: jhc0033@xxxxxxxxx
- Re: numbers as 'generics' parameters
- From: Gautier
- Re: numbers as 'generics' parameters
- From: Maciej Sobczak
- Re: numbers as 'generics' parameters
- From: Dmitry A. Kazakov
- Re: numbers as 'generics' parameters
- From: Maciej Sobczak
- Re: numbers as 'generics' parameters
- From: Dmitry A. Kazakov
- Re: numbers as 'generics' parameters
- From: Maciej Sobczak
- Re: numbers as 'generics' parameters
- From: Dmitry A. Kazakov
- Re: numbers as 'generics' parameters
- From: Maciej Sobczak
- numbers as 'generics' parameters
- Prev by Date: Re: memory management in Ada: tedious without GC?
- Next by Date: Pointer
- Previous by thread: Re: numbers as 'generics' parameters
- Next by thread: Re: numbers as 'generics' parameters
- Index(es):
Relevant Pages
|