|
| 1 | +with Ada.Containers.Vectors; |
| 2 | + |
| 3 | +procedure Main is |
| 4 | + -- Define an integer vector type |
| 5 | + |
| 6 | + package Integer_Vector |
| 7 | + is new Ada.Containers.Vectors |
| 8 | + (Index_Type => Natural,Element_Type => Integer); |
| 9 | + |
| 10 | + subtype Vector is Integer_Vector.Vector; |
| 11 | + |
| 12 | + -- Define a custom container with only "Add_Unnamed" assoc |
| 13 | + |
| 14 | + type Test_Container_1 is null record |
| 15 | + with Aggregate => (Empty => New_Empty, |
| 16 | + Add_Unnamed => Append); |
| 17 | + |
| 18 | + function New_Empty return Test_Container_1 is (null record); |
| 19 | + procedure Append (Self : in out Test_Container_1; |
| 20 | + Value : Integer) is null; |
| 21 | + |
| 22 | + -- Define a custom container with both "Add_Unnamed" and "New_Indexed" |
| 23 | + |
| 24 | + type Test_Container_2 is null record |
| 25 | + with Aggregate => (Empty => New_Empty, |
| 26 | + New_Indexed => New_Indexed_Cont, |
| 27 | + Add_Unnamed => Append, |
| 28 | + Assign_Indexed => Insert); |
| 29 | + |
| 30 | + function New_Empty return Test_Container_2 is (null record); |
| 31 | + function New_Indexed_Cont(X, Y : Integer) return Test_Container_2 is (null record); |
| 32 | + procedure Append (Self : in out Test_Container_2; |
| 33 | + Value : Integer) is null; |
| 34 | + procedure Insert (Self : in out Test_Container_2; |
| 35 | + Index : Integer; |
| 36 | + Value : Integer) is null; |
| 37 | + |
| 38 | + -- Create a derived container type |
| 39 | + |
| 40 | + subtype Derived_Container is Test_Container_2; |
| 41 | + |
| 42 | + -- Test container aggregate expressions |
| 43 | + |
| 44 | + V : Vector := [ 1, 2, 3, 4 ]; -- NOFLAG |
| 45 | + Copy : Vector := [ for E of V => E ]; -- FLAG |
| 46 | + Only_Even : Vector := [ for E of V when E mod 2 = 0 => E ]; -- FLAG |
| 47 | + |
| 48 | + C_1_1 : Test_Container_1 := [ 1, 2, 3, 4 ]; -- NOFLAG |
| 49 | + C_1_2 : Test_Container_1 := [ for E of V => E ]; -- NOFLAG |
| 50 | + C_2_1 : Test_Container_2 := [ 1, 2, 3, 4 ]; -- NOFLAG |
| 51 | + C_2_2 : Test_Container_2 := [ for E of V => E ]; -- FLAG |
| 52 | + D_C_1 : Derived_Container := [ 1, 2, 3, 4 ]; -- NOFLAG |
| 53 | + D_C_2 : Derived_Container := [ for E of V => E ]; -- FLAG |
| 54 | +begin |
| 55 | + null; |
| 56 | +end Main; |
0 commit comments