* What is the purpose of Vector.Query_Element?
@ 2015-07-26 22:09 EGarrulo
2015-07-26 23:02 ` Georg Bauhaus
2015-07-27 20:12 ` Randy Brukardt
0 siblings, 2 replies; 3+ messages in thread
From: EGarrulo @ 2015-07-26 22:09 UTC (permalink / raw)
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))`?
Thank you.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: What is the purpose of Vector.Query_Element?
2015-07-26 22:09 What is the purpose of Vector.Query_Element? EGarrulo
@ 2015-07-26 23:02 ` Georg Bauhaus
2015-07-27 20:12 ` Randy Brukardt
1 sibling, 0 replies; 3+ messages in thread
From: Georg Bauhaus @ 2015-07-26 23:02 UTC (permalink / raw)
On 27.07.15 00:09, EGarrulo wrote:
> 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?
To avoid copying.
"These procedures provide in situ access to an element."
-- Ada Rationale 2005 Ch 8.2.
http://www.adaic.org/resources/add_content/standards/05rat/html/Rat-8-2.html
> Isn't `Query_Element (Vector, Index, Process'Access)` the same as `Process (Element (Vector, Index))`?
Maybe the difference is a little more apparent when
considering Update_Element.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: What is the purpose of Vector.Query_Element?
2015-07-26 22:09 What is the purpose of Vector.Query_Element? EGarrulo
2015-07-26 23:02 ` Georg Bauhaus
@ 2015-07-27 20:12 ` Randy Brukardt
1 sibling, 0 replies; 3+ messages in thread
From: Randy Brukardt @ 2015-07-27 20:12 UTC (permalink / raw)
"EGarrulo" <egarrulo@gmail.com> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-07-27 20:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-26 22:09 What is the purpose of Vector.Query_Element? EGarrulo
2015-07-26 23:02 ` Georg Bauhaus
2015-07-27 20:12 ` Randy Brukardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox