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,8385fc6e4bf20336 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.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!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Generics with concrete and class-wide types 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: <279b6f4f-36cf-446f-8b54-fd72b957b22f@i7g2000prf.googlegroups.com> Date: Tue, 1 Apr 2008 11:42:18 +0200 Message-ID: <10v8f09pvzjs6$.1r7fruma1fer5$.dlg@40tude.net> NNTP-Posting-Date: 01 Apr 2008 11:42:18 CEST NNTP-Posting-Host: c31cf469.newsspool3.arcor-online.net X-Trace: DXC=\HQ`mlC7BaZ[7Non7UCi8UMcF=Q^Z^V3X4Fo<]lROoRQ^;5]aA^R6>RT`HEQ_c?<_[P]mB`6GMCS X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:20708 Date: 2008-04-01T11:42:18+02:00 List-Id: On Mon, 31 Mar 2008 13:22:10 -0700 (PDT), Maciej Sobczak wrote: > Consider a generic subprogram that makes sense for arguments of both > class-wide type and a concrete type. > > As a motivating example, there might be a hierarchy of iterator types > rooted in some imaginary Iterator type that is itself defined in the > generic package with the element type as its own formal parameter. > There are concrete iterator types that are derived from this root > Iterator type (exactly: from some instantiation thereof). > > There might be also a generic subprogram that operates on the iterator > given as its parameter. This subprogram takes two formal generic > parameters: the element type and the iterator type. > > Now - on one hand it makes sense to have a hierarchy of iterators and > benefit from loose coupling and other features of OO, but on the other > hand the iterators themselves can be lightweight objects that are used > in tight loops and we can expect them to be fast, therefore we could > benefit from *avoiding* the dynamic dispatch if there is enough > context to do so. > > Both make sense, depending on the context at the call site. > > To achieve both benefits the user might instantiate the subprogram for > the Iterator'Class type (to be exact: for the 'Class of some > instantiation of Iterator) in the context where only a class-wide type > is available, like within some other polymorphic subprogram; and for > the concrete type, like My_Concrete_Iterator, in the context where the > concrete type is available, with the hope that such an instantiation > can be more easily inlined. Just a small side note. If you care about performance you should do exactly the opposite you tried to, i.e. you should instantiate it with a specific type rather than with a class of. Doing so, you will force the compiler to resolve primitive operations statically without dispatching overhead. When you use class-wide, then its will dispatch somewhere, maybe later in the bodies, maybe more than once. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de