Debian Codegraph @

gcc/testsuite/gnat.dg/generic_inst19.adb

raw
1 -- { dg-do compile }
2
3 with Ada.Containers.Vectors;
4
5 procedure Generic_Inst19 is
6
7 generic
8 type T is private;
9 type Vector_Index is range <>;
10 -- Index and T_Array need to be placed here or T actual unconstrained
11 with package T_Vectors is new Ada.Containers.Vectors (Vector_Index, T);
12 type Index is range <>;
13 type T_Array is array (Index range <>) of T;
14 function To_Array_Generic (Vec : T_Vectors.Vector) return T_Array;
15
16 function To_Array_Generic (Vec : T_Vectors.Vector) return T_Array is
17 Result : T_Array (Index'First .. Index'First + Index (Vec.Length) - 1);
18 I : Index := Index'First;
19 begin
20 for X of Vec loop
21 Result (I) := X;
22 I := I + 1;
23 end loop;
24 return Result;
25 end To_Array_Generic;
26
27 type Probability is new Float range 0.0 .. 1.0;
28
29 package Probability_Vectors is new Ada.Containers.Vectors
30 (Index_Type => Positive, Element_Type => Probability);
31 type Probability_Array is array (Positive range <>) of Probability;
32
33 function To_Array is new To_Array_Generic (
34 T => Probability,
35 Vector_Index => Positive,
36 T_Vectors => Probability_Vectors,
37 Index => Positive,
38 T_Array => Probability_Array);
39
40 begin
41 null;
42 end;