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!news3.google.com!news2.volia.net!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> <1139645084.563448.239040@g47g2000cwa.googlegroups.com> Date: Sat, 11 Feb 2006 11:45:42 +0100 Message-ID: <1cfq4cp2jypst$.q1w29pgsumem$.dlg@40tude.net> NNTP-Posting-Date: 11 Feb 2006 11:45:31 MET NNTP-Posting-Host: 79f889a0.newsread4.arcor-online.net X-Trace: DXC=a`Dn32h_S?fGnN95NbAh:a:ejgIfPPlddjW\KbG]kaMhGAlE^3P3k5e On 11 Feb 2006 00:04:44 -0800, matteo.bordin@gmail.com wrote: > I will provide a proper example in C++. With this code I can prohibit > instantiation of template My_Class with T=int. > > class Checker{ > public: > static void check(float){}; > private: > static void check(int){}; > }; > > template > class My_Class{ > public: > My_Class(){ > T t; > Checker::check(t); > > } > }; > > int main(){ > > My_Class mc = My_Class(); //COMPILE TIME ERROR!!!! > //The error comes from the fact that Checker::check(int) is private > My_Class mc2 = My_Class(); //OK!!! > }; Your example in Ada would be: generic type T is digits <>; -- Only floating-point is allowed T is specified by its contract: a floating-point type, rather than using ad-hoc matching. It isn't clear what you are going to achieve using the technique like in your example. What if T were long? The trick you mention should be impossible in legal Ada, because generics are compilable separately [thank to the contract model.] So if any error may occur, then only in the formal part. [GNAT Ada has a lot of problems with this, but these are just bugs.] In means that any trick should rely on the formal parameter part. For example: generic type T is private; with function "+" (Left : T) return Float is <>; This will reject Integer and accept Float. But, again, it is an awful style. Now to your example. It has a direct Ada equivalent (checks are moved to the formal part): package Checker is function Check (T : Float) return Float renames "+"; end Checker; with Checker; use Checker; generic type T is private; wth function Check (X : T) return T is <>; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de