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: a07f3367d7,3ebfb7ec7bfb06fa X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.66.90.105 with SMTP id bv9mr1153344pab.18.1360469025487; Sat, 09 Feb 2013 20:03:45 -0800 (PST) MIME-Version: 1.0 Path: mj10ni888pbb.1!nntp.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!nrc-news.nrc.ca!goblin3!goblin.stu.neva.ru!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!munin.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Passing indefinite types Date: Mon, 4 Feb 2013 20:40:24 -0600 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <5262a822-409a-4c79-a842-0e716527cb70@googlegroups.com> <85ip696nlk.fsf@stephe-leake.org> <8d39b2ad-dc6c-4492-bc43-d2d01d748efa@googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1360032028 11579 69.95.181.76 (5 Feb 2013 02:40:28 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 5 Feb 2013 02:40:28 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Received-Bytes: 3052 Date: 2013-02-04T20:40:24-06:00 List-Id: wrote in message news:8d39b2ad-dc6c-4492-bc43-d2d01d748efa@googlegroups.com... On Sunday, February 3, 2013 5:26:15 PM UTC-5, Stephen Leake wrote: >> >> Could you show some almost legal code? > >I have found several occasions where this is useful (mostly for dealing >with classwide types >in constructing functions), but for an example consider something more >straightforward: >Suppose you want to write a subprogram that searches for a string pattern >within an >unconstrained number of other strings (and also suppose for the sake of >argument that >you cannot implement it as multiple calls to a subprogram that searches >within a single string). For this particular example, you ought to use an array of unbounded strings (or, if heap use has to be completely avoided, an array of bounded strings). QED. :-) The clear analog of this is either an array of holder containers, or a vector of indefinite items. I realize both of these use the heap, but really that shouldn't be a concern until/unless it is proven to be an issue. (Trying to avoid it initially is almost always premature optimization.) It hard to imagine doing too much with indefinite objects without resorting to the heap (or containers that use the heap) at some point. That's true for not just this problem, but pretty much any problem. The main reason to avoid heap use is worries about botched memory management, but that shouldn't be a concern if you use a predefined container or type like unbounded strings. If you truly need to avoid the heap (as per some embedded systems), I suspect you'll be forced to avoid indefinite types, too (other than as parameters as in class-wide or unconstrained array parameters). Just my 5 cents. Randy.