comp.lang.ada
 help / color / mirror / Atom feed
From: Blady <p.p11@orange.fr>
Subject: Generalized Loop Iteration and User-Defined Indexing with more than two parameters.
Date: Sun, 1 Nov 2020 19:41:50 +0100	[thread overview]
Message-ID: <rnmvhd$5b4$2@gioia.aioe.org> (raw)

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);
      9.       function Make (Value : String) return UXString;
     10.       function Length (Self : UXString) return Natural;
     11.       function Get (Self : UXString; Index : Positive; 
Substitute : in Character) return Character;
     12.       function First (Self : UXString) return Positive is (1);
     13.       function Next (Self : UXString; Index : Positive) return 
Positive is (Index + 1);
     14.       function Has_Element (Self : UXString; Index : Positive) 
return Boolean is (Index <= Self.Length);

The Get constant indexing function has more than two parameters.
GNAT 2020 compilation is ok with the "for ... in ... loop" form:

     47.    for I in S1 loop
     48.       C := S3 (I, '@');
     49.       Put_Line (Character'pos (C)'img);
     50.    end loop;

  but not with the "for ... of ... loop" form (S2 and S3 loops):

     51.    for CC of S2 loop
     52.       C := CC;
     53.       F := CC = 'h';
     54.       Put_Line (Character'pos (C)'img & F'img);
     55.    end loop;
test_uxstrings_4.adb:51:17: error: missing argument for parameter 
"Substitute" in call to "Get" declared at line 11

     56.    for CC of S3 ('@') loop
     57.       C := CC;
     58.       F := CC = 'h';
     59.       Put_Line (Character'pos (C)'img & F'img);
     60.    end loop;
test_uxstrings_4.adb:56:14: error: container cannot be indexed with "A 
Character Type"

What is the correct usage?

Thanks, Pascal.


             reply	other threads:[~2020-11-01 18:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-01 18:41 Blady [this message]
2020-11-03 11:05 ` Generalized Loop Iteration and User-Defined Indexing with more than two parameters Stephen Leake
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