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,fc52c633190162e0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!d57g2000hsg.googlegroups.com!not-for-mail From: "jimmaureenrogers@worldnet.att.net" Newsgroups: comp.lang.ada Subject: Re: why learn C? Date: 13 Apr 2007 18:20:22 -0700 Organization: http://groups.google.com Message-ID: <1176513622.003168.143490@d57g2000hsg.googlegroups.com> References: <1172144043.746296.44680@m58g2000cwm.googlegroups.com> <1172161751.573558.24140@h3g2000cwc.googlegroups.com> <546qkhF1tr7dtU1@mid.individual.net> <5ZULh.48$YL5.40@newssvr29.news.prodigy.net> <1175215906.645110.217810@e65g2000hsc.googlegroups.com> <1175230700.925143.28490@n59g2000hsh.googlegroups.com> <6XbPh.4025$u03.802@newssvr21.news.prodigy.net> <1175491660.511530.58430@y80g2000hsf.googlegroups.com> <1175566924.442636.199470@o5g2000hsb.googlegroups.com> NNTP-Posting-Host: 75.70.221.169 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1176513622 23631 127.0.0.1 (14 Apr 2007 01:20:22 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 14 Apr 2007 01:20:22 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: d57g2000hsg.googlegroups.com; posting-host=75.70.221.169; posting-account=SqOfxAwAAAAkL81YAPGH1JdBwpUXw9ZG Xref: g2news1.google.com comp.lang.ada:15005 Date: 2007-04-13T18:20:22-07:00 List-Id: On Apr 12, 9:47 am, Hyman Rosen wrote: > jimmaureenrog...@worldnet.att.net wrote: > > one cannot write a C++ template to handle range-specified > > > floating point classes. > > Of course this is wrong. Every floating point number that you > write in a program is in fact a rational number, and therefore > depending on the purpose those numbers will have in the template, > they be represented using small sets of integers in a variety of > ways. The template itself can then assemble these parts into a > floating-point constant and use it. Or if that's too burdensome, > references to floating-point variables are permitted, so getting > what you want looks rather like Ada generic instantiation. > > > But you cannot write a template equivalent to: > > type Voltage_Type is digits 11 range -5.0..5.0; > > Using the variable reference approach, we can do > > template class FloatRange; > extern double const vtlo = -5.0; > extern double const vthi = 5.0; > typedef FloatRange Voltage_Type; Your example relies upon passing pre-defined constants for the parameters lo and hi. It also allows you to specify whatever type is aliased by typename T. How does this template ensure that typename T is an alias for a floating point type? It appears that T could be instantiated with any type, including for instance the String type. C++ template syntax provides no way to pass float or double literals for the parameters lo and hi. It also provides no syntax to ensure that typename T is a floating point type. These deficiencies render your example not equivalent to the Ada example. Furthermore, they are weaknesses that are not a problem in the Ada generic formal parameter syntax. Jim Rogers