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-27 08:04:41 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: kcline17@hotmail.com (Kevin Cline) Newsgroups: comp.lang.ada Subject: Re: Anybody in US using ADA ? One silly idea.. Date: 27 Jan 2003 08:04:40 -0800 Organization: http://groups.google.com/ Message-ID: References: <1042743579.1165@master.nyc.kbcfp.com> <1042824191.538184@master.nyc.kbcfp.com> <_VkW9.266404$FT6.43771824@news4.srv.hcvlny.cv.net> NNTP-Posting-Host: 192.76.54.20 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1043683481 25805 127.0.0.1 (27 Jan 2003 16:04:41 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 27 Jan 2003 16:04:41 GMT Xref: archiver1.google.com comp.lang.ada:33457 Date: 2003-01-27T16:04:41+00:00 List-Id: Dmitry A. Kazakov wrote in message news:... > On 21 Jan 2003 10:55:36 -0800, kcline17@hotmail.com (Kevin Cline) > wrote: > > >Dmitry A. Kazakov wrote in message news:... > >> On Tue, 21 Jan 2003 02:10:37 GMT, "Hillel Y. Sims" > >> wrote: > >> > >> >"Dmitry A. Kazakov" wrote in message > >> >news:b0e5vu$ognn6$1@ID-77047.news.dfncis.de... > >> >> Hillel Y. Sims wrote: > >> >> > [templated C++ sort() is faster than qsort()] > >> >> > >> >> This is a wrong comparison. A correct one would be an instance of a > generic > >> >> subroutine vs. an inlined subroutine and, note, when the type is > statically > >> >> known. > >> > > >> >sort() vs. sort_ints()? In that case the performance should really be > >> >exactly the same (since as you say, it really *is* to a large extent just a > >> >bunch of text substitution :-). The benefit is that you don't need to > >> >rewrite or copy/paste the code over and over for each unique type, the > >> >compiler does it automatically (while maintaining full type safety, unlike > >> >dumb macros) -- and better yet, when you fix a bug in the generic version, > >> >it is immediately fixed for all instantiations automatically (vs. > >> >sort_ints(), sort_floats(), sort_strings(), sort_xyz()) > >> > >> This is an advantage of generics over blind preprocessing. The problem > >> is whether same can be achieved without both. > >> > >> Consider class-wide sort written for all arrays derived from some > >> abstract array of comparable elements. If that sort is inlined, then > >> then compiler theoretically would have all necessary information to > >> make code as efficient as generic sort could. Presently it is > >> impossible in both Ada and C++. > > > >But then to be sortable the element type would have be derived from > >some "Comparable" base type. And to be stored in a hash table, > >they would have to be derived from a "Hashable" base type. And to be > >used with some generic mathematical algorithm they would have to > >be derived from an "Arithmetic" base type... > > Yes of course. Derived here means only "implements interface of". It > is also an advantage over generics, because with templates you never > know if the actual type is "Hashable", until you instantiate all > functions using all methods of "Hashable". And even so, nobody can say > whether these methods really comprise a "Hashable" type or they just > have similar names and the profiles appropriate to go through the > compiler. This would prevent the instantiation of generics on any built-in types, or on any type defined in a library.