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!news4.google.com!feeder.news-service.com!newsfeed.freenet.de!newsfeed01.chello.at!newsfeed.arcor.de!newsspool2.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> <1g4p2jgvi3k8j.1j2xk6p9ws3a2.dlg@40tude.net> <9e99c5cd-fd94-4a38-89fd-681c0372b7ad@y38g2000hsy.googlegroups.com> <1nng3xn67do3n$.1f4isrrr1y1m2.dlg@40tude.net> <0ebf73b9-4c38-4279-99de-da230e978c83@k37g2000hsf.googlegroups.com> Date: Mon, 19 May 2008 11:02:27 +0200 Message-ID: NNTP-Posting-Date: 19 May 2008 11:02:27 CEST NNTP-Posting-Host: b8b1f505.newsspool3.arcor-online.net X-Trace: DXC=BIgP0kX4RTdOKO]LCQ@0g`McF=Q^Z^V3h4Fo<]lROoRa8kF?kNZ@k[6LHn;2LCVn7enW;^6ZC`dIXm65S@:3>oEEi2j:E:Uhh X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:227 Date: 2008-05-19T11:02:27+02:00 List-Id: On Sun, 18 May 2008 13:37:47 -0700 (PDT), Maciej Sobczak wrote: > On 18 Maj, 16:52, "Dmitry A. Kazakov" > 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 > void foo(const fixed_size_string & 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