From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: What is the purpose of Vector.Query_Element?
Date: Mon, 27 Jul 2015 15:12:18 -0500
Date: 2015-07-27T15:12:18-05:00 [thread overview]
Message-ID: <mp63b3$9t8$1@loke.gir.dk> (raw)
In-Reply-To: ca22434f-8216-4cbd-a4c0-46fea8e6cc98@googlegroups.com
"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.
prev parent reply other threads:[~2015-07-27 20:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox