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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,103b407e8b68350b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-23 02:56:10 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Anybody in US using ADA ? One silly idea.. Date: Thu, 23 Jan 2003 12:00:34 +0100 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: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1043319369 29270026 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:33367 Date: 2003-01-23T12:00:34+01:00 List-Id: 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. --- Regards, Dmitry Kazakov www.dmitry-kazakov.de