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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,103b407e8b68350b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-17 12:02:33 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!snoopy.risq.qc.ca!newshub.northeast.verio.net!verio!nntp.abs.net!uunet!dca.uu.net!ash.uu.net!spool0902.news.uu.net!not-for-mail Date: Fri, 17 Jan 2003 15:02:01 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3b) Gecko/20030116 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Anybody in US using ADA ? One silly idea.. References: <1041908422.928308@master.nyc.kbcfp.com> <1041997309.165001@master.nyc.kbcfp.com> <1042086217.253468@master.nyc.kbcfp.com> <1042477504.547640@master.nyc.kbcfp.com> <1042651417.215661@master.nyc.kbcfp.com> <1042743579.1165@master.nyc.kbcfp.com> <1042824191.538184@master.nyc.kbcfp.com> <3E28534F.DD4016C3@adaworks.com> In-Reply-To: <3E28534F.DD4016C3@adaworks.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1042833721.656780@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1042833723 20826 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:33158 Date: 2003-01-17T15:02:01-05:00 List-Id: Richard Riehle wrote: > Here is a generic in Ada, which while not identical to the C++ model, > does permit combining specialization with genericity and which has > turned out to be quite useful for certain kinds of problems. This looks like something we would write in C++ like this: template struct Starting_Type : public Item { void Make(); }; I agree - there are plenty or circumstances where this is useful and powerful. C++ template specialization is different though; it doesn't (necessarily) involve tagged types at all. Here's a simple example: // General case template struct Factorial { enum { Value = N * Factorial::Value } }; // Specialization for 0 template<> struct Factorial<0> { enum { Value = 1 } }; // Use it, as a compile-time constant expression int array[Factorial<5>::Value]; When you ask for Factorial<0>, the compiler uses the special case you provided, otherwise it uses the general case. Notice that the bodies of the specialization is completely different from the one in the general case. (They both define a Value enumerator, but in general, they could have been completely unrelated.) The same thing works for type parameters: // General case template struct RemovePointers { typedef T type; }; // Specialize for pointers template struct RemovePointers { typedef RemovePointers::type type; }; RemovePointers::type its_a_double = 17.29; When you ask for RemovePointers, the compiler matches SomeType against the specializatons. If it finds that one of them is a better match than the generic type (using rules defined by the language), it uses that one.