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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a84eaf8fb2470909 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ada generics Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1166710494.869393.108730@a3g2000cwd.googlegroups.com> <17fe4xfogg7p5.1dcyc5nyc2gsl.dlg@40tude.net> <1166805696.291429.239590@48g2000cwx.googlegroups.com> Date: Mon, 25 Dec 2006 15:39:03 +0100 Message-ID: <186qujlcx6rwl.1h6eq4mbdaa5s$.dlg@40tude.net> NNTP-Posting-Date: 25 Dec 2006 15:39:01 CET NNTP-Posting-Host: 72859966.newsspool1.arcor-online.net X-Trace: DXC=0B[`]A_a@PI2jYf>V4L0gLic==]BZ:afN4Fo<]lROoRA^YC2XCjHcbIhWXNQgB4?MKDNcfSJ;bb[EIRnRBaCd On Mon, 25 Dec 2006 13:49:23 GMT, Hyman Rosen wrote: > Dmitry A. Kazakov wrote: >> Automatic conversions do not represent any special case. If S is >> convertible to T, then S is a subtype of T > > That simply is not the case in C++. Automatic conversions do not > define subtypes in any meaningful or useful sense. For example, > all the numeric types automatically convert to each other. It's > also possible to write automatic conversions between arbitrary > classes. Ah, but it is not required for S<:T & T<:S be wrong. Two types can be subtypes of each other like int and float are in C. It is a common misconception about subtypes to believe that either must not hold. Observe, that it is wrong in Ada either. Consider this: type T is range 1..100; subtype S is T; procedure Exported_To_Base (X : in out S); X : T; begin Exported_To_Base (X); -- It is fine! See, the operation Exported_To_Base defined on S was exported to the base type T. In other words T inherits it from S, which is equivalent to say that T is a subtype of S. T and S are sub-/supertypes of each other. >> Exactly. The idea of structural matching is wrong. > > It's not wrong, and it's not even structural. It is in fact > matching by name, not by structure. But in foo<123>, 123 is not a name. It could be in some other language where I could do: int 123() const { return ::124; // (:-)) } But that would make many of instantiations ambiguous. > It's only in the case of > constant expressions that things go a little awry. But if you > recall the discussions we've had here on implementing units, > it lets C++ do things that are impossible in Ada. You mean automatic instantiation here, but I don't want it. I also don't want this solution for this problem. I even dare say that this is a bad solution for *any* problem. Looking a bit more deeply into the issue, there are two things to address: 1. compile-time computations 2. types computations (types algebra) Generics and templates offer some quite weird and limited way to have 1. and 2. Ask yourself, is it the only way? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de