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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: What is the purpose of Vector.Query_Element? Date: Mon, 27 Jul 2015 15:12:18 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1438027939 10152 24.196.82.226 (27 Jul 2015 20:12:19 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 27 Jul 2015 20:12:19 +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 Xref: news.eternal-september.org comp.lang.ada:27047 Date: 2015-07-27T15:12:18-05:00 List-Id: "EGarrulo" wrote in message news:ca22434f-8216-4cbd-a4c0-46fea8e6cc98@googlegroups.com... > The package that defines Vector provides this procedure: > > procedure Query_Element > (Container : in Vector; > Index : in Index_Type; > Process : not null access procedure (Element : in Element_Type)); > > Why is this procedure provided? Isn't `Query_Element (Vector, Index, > Process'Access)` the same as `Process (Element (Vector, Index))`? Sure, if you don't care about performance they're the same. But a function result is a copy of the element ("Element" is a function), whereas Query_Element can pass the element by reference (and will for most types that aren't by-copy); in that case it is directly referenced in place. For large elements (say, like other containers), the overhead of copying could be considerable. OTOH, if the element is a by-copy type, there is no difference. So Query_Element is a specialized need. Besides, for Ada 2012, you probably ought to be using the indexing syntax and not use either of these. Randy.