From: "Thomas Løcke" <thomas.granvej6@gmail.com>
Subject: Vectors.Insert_Space bug?
Date: Wed, 20 May 2009 22:59:45 +0200
Date: 2009-05-20T22:59:45+02:00 [thread overview]
Message-ID: <4a146f41$0$90265$14726298@news.sunsite.dk> (raw)
Hey all,
I've stumbled on some weird behavior while trying to make use of the
Ada.Containers.Vectors.Insert_Space procedure. According to the RM, this
is what it should do:
"... Then Insert_Space slides the elements in the range Before ..
Last_Index (Container) up by Count positions, and then inserts empty
elements in the positions starting at Before."
But that is not at all what I'm seeing, as this small test-program will
show:
-- Pasted code start --
with Ada.Text_IO.Unbounded_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Containers.Vectors; use Ada.Containers;
procedure Test is
package SUIO renames Ada.Text_IO.Unbounded_IO;
package US_Container is new Vectors (Positive, Unbounded_String);
Testing : US_Container.Vector;
begin
Testing.Append (New_Item => To_Unbounded_String ("Item 1"));
Testing.Append (New_Item => To_Unbounded_String ("Item 2"));
Testing.Append (New_Item => To_Unbounded_String ("Item 3"));
Testing.Append (New_Item => To_Unbounded_String ("Item 4"));
Testing.Append (New_Item => To_Unbounded_String ("Item 5"));
Testing.Insert_Space (Before => 5,
Count => 3);
for i in 1 .. Testing.Length loop
SUIO.Put_Line (i'Img & " " & Testing.Element (Integer (i)));
end loop;
end Test;
-- Pasted code end --
The output from the Test program is:
1 Item 1
2 Item 2
3 Item 3
4 Item 4
5 Item 5
6
7
8 Item 5
Which IMHO is wrong. There shouldn't be two "Item 5" elements. And it's
possible to make it even worse, by calling Insert_Space multiple times
with different Before and Count parameters.
It seems as if the element located at the Before index is copied and
inserted as the first new element, and only after that, does
Insert_Space actually start inserting empty elements.
I've tried to compile with two different compilers, and both exhibit
this odd behavior:
GNATMAKE 4.2.3
GNATMAKE GPL 2008 (20080521)
I admit to just being a hobbyist, so this might just be me not "getting"
what the RM is trying to tell me, but I do think the text is fairly clear.
Any help would be greatly appreciated.
Regards,
Thomas L�cke
next reply other threads:[~2009-05-20 20:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-20 20:59 Thomas Løcke [this message]
2009-05-21 1:56 ` Vectors.Insert_Space bug? John B. Matthews
2009-05-22 5:07 ` Thomas Løcke
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox