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,262b74f44c7f873e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: prohibit certain generic instantiations in Ada 2005 Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.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: <1139508110.410006.28260@g14g2000cwa.googlegroups.com> <1139515341.782860.197930@f14g2000cwb.googlegroups.com> <1139581110.636535.107910@g44g2000cwa.googlegroups.com> Date: Fri, 10 Feb 2006 19:25:24 +0100 Message-ID: NNTP-Posting-Date: 10 Feb 2006 19:25:15 MET NNTP-Posting-Host: 872fad5f.newsread4.arcor-online.net X-Trace: DXC=l2l:K\9EhFjCUhGd:LVK2e:ejgIfPPlddjW\KbG]kaMh8nDPh04j=Qo>S20kkdKATkmWkfB4cNm_`gT\1QI\6KSo>@oQDQ5e`Sf X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:2844 Date: 2006-02-10T19:25:15+01:00 List-Id: On 10 Feb 2006 06:18:30 -0800, matteo.bordin@gmail.com wrote: > I understand and agree from a semantic point of view. However I would > like to let the compiler perform some additional type checking on the > generic instance. If the generic instantiation is not allowed, then I > what the compiler to produce a compilation error. This makes sense if > you are using generics as a generative tool for metaprogramming. This > kind of things can be done in C++, which has a compilation model > similar to Ada (for what concerns generics/templates). I don't see how you came to this conclusion. C++ model is quite different, especially with respect of your question - it isn't contract based. So, basically, C++ is unable to check anything specific about the type of template a parameter. Ada's model is contract based, so types are fully checked. That in particular means, that there cannot be any "additional type" checking. Probably you meant something else. Note that the type contract can be strengthen in Ada by requiring some additional subroutines. For example: generic type S is new T with private; procedure Ad_Hoc (X : in out S) is <>; Here we require a type from T'Class plus some procedure Ad_Hoc defined on it. However, it is a *bad* practice from software design perspective inherited from Ada 83, which wasn't OO. A proper way is to make T'Class + Ad_Hoc explicit. If, for whatever reason, T is frozen, you should, as Matthew suggested, derive a new [maybe abstract] base: type T1 is abstract T with null record; procedure Ad_Hoc (X : in out T1) is abstract; -- This is a proper contract now generic type S is new T1 with private; -- Here we use the contract -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de