# Overloaded iterations with "of"

**URL:** https://forum.ada-lang.io/t/overloaded-iterations-with-of/4594
**Category:** Help
**Created:** [July 27, 2026, 7:58pm UTC](https://forum.ada-lang.io/t/overloaded-iterations-with-of/4594 "2026-07-27T19:58:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Blady](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/b/e9bcb4/32.png) [@Blady](https://forum.ada-lang.io/u/Blady)
#### Post date: [July 27, 2026, 7:58pm UTC](https://forum.ada-lang.io/t/overloaded-iterations-with-of/4594/1 "2026-07-27T19:58:31Z")

</div>

I was pretty happy to use overload functionality of Constant\_Indexing with my container:  
(Source code available upon request)

```ada
4. package USXStrings is 
5. type UXString is tagged record 
6. Data : Wide_Wide_String (1 .. 10); 
7. end record with 
8. Constant_Indexing => Get, 
9. Iterable => (First => First, Next => Next, Has_Element => Has_Element, Element => Get); 
... 
12. function Get (Self : UXString; Index : Positive) return Character is (To_Character (Self.Data (Index))); 
13. function Get (Self : UXString; Index : Positive) return Wide_Character is (To_Wide_Character (Self.Data (Index))); 
14. function Get (Self : UXString; Index : Positive) return Wide_Wide_Character is (Self.Data (Index)); 
... 
18. end USXStrings;

```

Thus I’m able to get the element of the chosen type:

```ada
21. S1, S2, S3 : UXString; 
22. C : Character; 
23. WC : Wide_Character; 
24. WWC : Wide_Wide_Character; 
... 
31. C := S1 (3); 
32. WC := S1 (2); 
33. WWC := S1 (1);

```

Moreover, I want to iterate with “of”:

```ada
41. for CC : Character of S1 loop 
42. C := CC; 
43. F := CC = 'h'; 
44. Put_Line (Character'pos (C)'img & F'img); 
45. end loop; 
46. for CC : Wide_Character of S2 loop 
47. WC := CC; 
48. F := CC = 't'; 
49. Put_Line (Wide_Character'pos (WC)'img & F'img); 
50. end loop; 
51. for CC : Wide_Wide_Character of S3 loop 
52. WWC := CC; 
53. F := CC = '4'; 
54. Put_Line (Wide_Wide_Character'pos (WWC)'img & F'img); 
55. end loop;

```

But I got errors:

```ada
test_uxstrings_2.adb:41:13: error: subtype indication does not match element type "Wide_Wide_Character"
test_uxstrings_2.adb:42:13: error: expected type "Standard.Character"
test_uxstrings_2.adb:42:13: error: found type "Standard.Wide_Wide_Character"
test_uxstrings_2.adb:46:13: error: subtype indication does not match element type "Wide_Wide_Character"
test_uxstrings_2.adb:47:13: error: expected type "Standard.Wide_Character"
test_uxstrings_2.adb:47:13: error: found type "Standard.Wide_Wide_Character"

```

Only the third loop (line 51) is compiling ok.

Is it a compiler issue or is there something in Ada standard which prevents the two first loops?

---

<div class="post-metadata">

### Author: ![cantanima](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cantanima/32/121_2.png) [@cantanima](https://forum.ada-lang.io/u/cantanima)
#### Post date: [July 27, 2026, 11:28pm UTC](https://forum.ada-lang.io/t/overloaded-iterations-with-of/4594/2 "2026-07-27T23:28:09Z")

</div>

Maybe I misunderstand your question, but first you have to specify `Default_Iterator` and `Iterator_Element` (at least). See RM 5.5.1.

---

<div class="post-metadata">

### Author: ![Blady](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/b/e9bcb4/32.png) [@Blady](https://forum.ada-lang.io/u/Blady)
#### Post date: [July 28, 2026, 6:57pm UTC](https://forum.ada-lang.io/t/overloaded-iterations-with-of/4594/3 "2026-07-28T18:57:48Z")

</div>

Sorry, I forgot to specify that the iterator was GNAT-specific (see [documentation](https://docs.adacore.com/gnat_rm-docs/html/gnat_rm/gnat_rm/implementation_defined_aspects.html#aspect-iterable)).
