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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,30352abc52760363 X-Google-Attributes: gid103376,public X-Google-Thread: fc772,638fa84e87ee92f3 X-Google-Attributes: gidfc772,public From: Brian Rogoff Subject: Re: Ada to C++ Translators Date: 1998/02/23 Message-ID: <6cs8ml$188@netlab.cs.rpi.edu>#1/1 X-Deja-AN: 327876376 Sender: cppmods@netlab.cs.rpi.edu References: <34E47622.15EB@atc-1s.hac.com> <1998Feb13.213046.1@eisner> <6c9tjc$obg@universe.digex.net> <34eb5d36.20077308@news.tiac.net> <6ceq7m$3nc@universe.digex.net> <6cn8lg$cao@netlab.cs.rpi.edu> X-Submission-Address: c++-submit@netlab.cs.rpi.edu X-Original-Date: Sat, 21 Feb 1998 15:12:54 -0800 Organization: unknown Newsgroups: comp.lang.c++.moderated,comp.lang.ada Date: 1998-02-23T00:00:00+00:00 List-Id: On 21 Feb 1998, Esa Pulkkinen wrote: > [Sorry this is a bit off-topic for comp.lang.ada, so I'll crosspost and > put followups to comp.lang.c++.moderated.] I think it is perfectly appropriate for comp.lang.ada, as long as language warriors restrain themselves. > Brian Rogoff writes at comp.lang.ada: > > I'd be interested in hearing how a well designed Ada program that makes > > use of constrained genericity gets translated to a well designed C++ > > program. I haven't been following the C++ standard for a while, but I > > thought that there was no constrained genericity in C++, and that the > > work-arounds would not really be considered "well-designed". > > See http://www.cs.tut.fi/~esap/instructive/ for one method for > converting a program which uses constrained genericity to C++ using > class template partial specialization. It uses class template partial > specialization to implement different versions of the class for the case > where the class is derived from another class, and for the case where it > isn't. I think it's as well-designed as it ever will without explicit > language support, but I'd like to hear your opinions. Very interesting; the workaround I am familiar with is the one where you do an assignment to the constraint type in some method. I'll certainly try your method out next time I have a capable C++ compiler. Still, I have some issues, namely (1) What if the generic parameters being constrained are not tagged types/classes? In the case of Ada, there are generic constraints to match all of the types in the language. This is not such a big deal in C++, since you don't have ranges, but it surely does make such a translation harder. (2) Function and procedure parameters. I assume you'd just wrap these up in classes, right? That's a bit tedious. (3) Formal package parameters. This is my favorite "gee-whiz" feature of Ada 95. It's related to (1) and (2) in that I can (and do!) bundle up non-tagged generic abstractions (like Stacks and Dictionaries say) and then use instantiations of both with their actual parameters constrained to be the same. Once again, it seems with your translation I have to first make everything a class. That said, I think your translation is a very neat trick. In a "feature restrained" program, done in a very stylized way, it would work, but I fear that a straightforward and idiomatic Ada 95 program would not translate to a similarly straightforward (Draft) ISO C++ program. Almost all of my Ada code uses constrained genericity somewhere. -- Brian [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ] [ about comp.lang.c++.moderated. First time posters: do this! ]