I was pretty happy to use overload functionality of Constant_Indexing with my container:
(Source code available upon request)
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:
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”:
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:
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?