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,1dd28d5040ded1f8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-15 11:34:18 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!hammer.uoregon.edu!skates!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: Announce: Grace project site operational Date: 15 May 2002 14:15:43 -0400 Organization: NASA Goddard Space Flight Center (skates.gsfc.nasa.gov) Message-ID: References: <4519e058.0205140718.3ddb1b2a@posting.google.com> <3CE15D0A.3050100@mail.com> <3ce21f37$1@pull.gecm.com> NNTP-Posting-Host: anarres.gsfc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: skates.gsfc.nasa.gov 1021486970 23602 128.183.220.71 (15 May 2002 18:22:50 GMT) X-Complaints-To: usenet@news.gsfc.nasa.gov NNTP-Posting-Date: 15 May 2002 18:22:50 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:24111 Date: 2002-05-15T18:22:50+00:00 List-Id: "Martin Dowie" writes: > "Hyman Rosen" wrote in message > news:3CE15D0A.3050100@mail.com... > [snip] > > I first saw this idiom in _Scientific and Engineering C++_ > > by Bartion & Nackman. > > > > template > > struct Unit > > { > > RepType value; > > explicit Unit(value) : value(value) { } > > Unit operator+(Unit other) > > { return Unit(value + other.value); } > > Unit operator-(Unit other) > > { return Unit(value - other.value); } > > }; > [snip] > > Didn't someone post an Ada units package similar to > this a while back (> 1 year)?.. Yes, there are several similar Ada packages. But, all the Ada packages either have run-time overhead (the Mass, Distance, Time values are stored in the type, and computed and checked at run-time), or suffer from combinatoric explosion of types. The C++ template solution apparently computes and checks the Mass, Distance, and Time values at _compile_ time, so there is no runtime overhead. There is, in effect, the same combinatoric explosion of types (actually operators in this case), but it is handled automatically by the compiler, thru implicit instantiation (is that the right term?). And only those operators that are actually used are ever declared, and the _user_ only has to write the templates, not the instantiations. This is pretty neat. One area where C++ templates are superior to Ada generics (as others have been saying all along :). -- -- Stephe