Hello,
Could someone please try to compile/run the program below?
When I compile it, I get the following error:
—————————————————————————————–
test1.adb:16:04: error: instantiation error at a-coinve.ads:533
test1.adb:16:04: error: “Empty_Vector” conflicts with declaration at a-coinve.ads:533, instance at line 16 compilation of test1.adb failed
——————————————————————————————
When I remove the if
construct, the compiler does not complain.
I use debian/alire 2.1.0
reinert
with Ada.Text_IO;
with Ada.Containers.Indefinite_Vectors;
procedure Test1 is
use Ada.Containers;
use Ada.Text_IO;
function Is_Number1 (X : String) return Boolean is
A : Float;
begin
A := Float'Value (X);
return True;
exception
when others => return False;
end Is_Number1;
package Arg1_P is new Indefinite_Vectors (Positive, String);
type Condition1_T is access function (X : String) return Boolean;
function Find_Index1
(X : Arg1_P.Vector;
Condition1 : Condition1_T;
Forward1 : Boolean := True) return Integer
is
begin
if Forward1 then
for I in X.First_Index .. X.Last_Index loop
return I when Condition1 (X (I));
end loop;
-- else
-- for I in reverse X.First_Index .. X.Last_Index loop
-- return I when Condition1 (X (I));
-- end loop;
end if;
return Arg1_P.No_Index;
end Find_Index1;
A : constant Arg1_P.Vector :=
["aa", "bbb", "23", "56.78", "hhh", "iiii"];
I1 : constant Integer := Find_Index1 (A, Is_Number1'Access, Forward1 => True);
I2 : constant Integer := Find_Index1 (A, Is_Number1'Access, Forward1 => False);
begin
Put_Line ("a: " & A'Image);
Put_Line ("i1, i2 : " & I1'Image & I2'Image);
end Test1;