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,f7a9613bbc2bd8c9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-13 08:02:38 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!news.gtei.net!nntp.abs.net!uunet!dca.uu.net!ash.uu.net!spool0901.news.uu.net!spool0900.news.uu.net!reader0901.news.uu.net!not-for-mail Message-ID: <3CDFD5C3.1070801@mail.com> Date: Mon, 13 May 2002 11:03:31 -0400 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.0rc1) Gecko/20020417 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Generic default parameters References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Cache-Post-Path: master.nyc.kbcfp.com!unknown@mosquito.nyc.kbcfp.com X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1021302156 reader1.ash.ops.us.uu.net 5137 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:23960 Date: 2002-05-13T11:03:31-04:00 List-Id: Simon Wright wrote: > I think what you're discussing here is related to "traits" in the C++ > world??? (something that's a black mystery to me). Or perhaps it's > "partial specialization". Let me try to explain what these are. In C++, the equivalent of an Ada generic package is a class template. In Ada, once you have a generic package, it is a fixed thing. You can instantiate man packages from the generic, but they all share the same specification and implementation code. In C++, you can write a partial specialization, which causes an entirely different declaration and implementation code to be used when the template is instantiated for certain values of the generic parameters. (A refinement of this is the explicit specialization, which is a specialization written for a single set of generic parameter values.) Here's a silly example of a compile-time factorial calculator: // generic template template struct factorial { enum { val = N * factorial::val }; }; // specialization for N == 0 template<> struct factorial<0> { enum { val = 1 }; }; int f6 = factorial<6>::val; // evaluates to 720 at compile-time The compiler uses the generic template unless the template parameter is zero, whereupon it uses the special case provided. Then you can think of traits as the equivalent of Ada having user-defined attributes. You write a class template that contains type definitions or constants pertaining to a type, that you can't get from the compiler itself, and then you write specializations for the types you need. > Anyway, this would be very useful, I think, in simplifying a complex > generic arrangement like the BCs'. Yes, that's exactly the idea.