comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Generalized Loop Iteration and User-Defined Indexing with more than two parameters.
Date: Tue, 03 Nov 2020 03:05:50 -0800	[thread overview]
Message-ID: <86361qwvht.fsf@stephe-leake.org> (raw)
In-Reply-To: rnmvhd$5b4$2@gioia.aioe.org

Blady <p.p11@orange.fr> writes:

> Hello,
>
> Let's take the following container with constant indexing for iteration:
>
>      6.       type UXString is tagged private with
>      7.          Constant_Indexing => Get,
>      8.          Iterable          => (First => First, Next => Next,
> Has_Element => Has_Element, Element => Get);

>     11.       function Get (Self : UXString; Index : Positive;
> Substitute : in Character) return Character;

Hmm. Aspect "Iterable" is not defined by Ada. It is defined by GNAT. The
gnat reference manual says:

   * The value of `Element' is a primitive operation of the container
     type that takes both a container and a cursor and yields an
     `Element_Type', which must be a type declared in the container
     package or visible from it. For example:

    function Get_Element (Cont : Container; Position : Cursor) return Element_Type;

So it should have complained that your "Element => Get" is illegal.

> What is the correct usage?

An iterator 'Element' function can take only two parameters; the same is
true for standard Ada generalized iterators.

A Constant_Indexing function can take more than two parameters, but you
can only use it by indexing a container object directly (see LRM 4.1.6), 

A : UXString;

for Position in A.First .. A.Last loop

    Foo := A (Position, Substitute => 'C');
    ...
    
-- 
-- Stephe

  reply	other threads:[~2020-11-03 11:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-01 18:41 Generalized Loop Iteration and User-Defined Indexing with more than two parameters Blady
2020-11-03 11:05 ` Stephen Leake [this message]
2020-11-06 15:39   ` Blady
2020-11-07  0:58     ` Randy Brukardt
2020-11-07 17:46       ` Blady
2020-11-10  1:45         ` Randy Brukardt
2020-11-07 23:54       ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox