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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newspeer.monmouth.com!chiapp19.algx.com!allegiance!nntp.abs.net!news.abs.net!not-for-mail Newsgroups: comp.lang.ada Subject: Re: prohibit certain generic instantiations in Ada 2005 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> From: Stephen Leake Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt) Cancel-Lock: sha1:rdEo6Ox+QmRxshi6yYo1emjb7XU= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 11 Feb 2006 10:36:58 -0500 NNTP-Posting-Host: 66.159.65.1 X-Complaints-To: abuse@toad.net X-Trace: news.abs.net 1139672218 66.159.65.1 (Sat, 11 Feb 2006 10:36:58 EST) NNTP-Posting-Date: Sat, 11 Feb 2006 10:36:58 EST Xref: g2news1.google.com comp.lang.ada:2862 Date: 2006-02-11T10:36:58-05:00 List-Id: matteo.bordin@gmail.com writes: > 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!!! > }; > > When I said that the compilation model for template of Ada is similar > to C++, I meant in regards to compile-time code generation (opposed to > the model of Java generics). In both languages (Ada and C++), templates > can be used as a generative environment. Ok, you _can_ do this in C++. But they question remains; _why_ do you want to do this? What is it that Checker does that is appropriate for all types, except 'int'? > > just want to know f here is a way to reproduce the C++ code I > provided in Ada (2005). You can write code in the execution part of a package body (after the 'begin') that does some checking, and raises an exception. Most compilers will warn at compile time that a run-time construct will raise an exception. -- -- Stephe