* contrib-list.mk (LIST): Remove arm-freebsd6, arm-linux,
[official-gcc.git] / gcc / ada / a-cofove.adb
blob8900e054cb818a7cf53d0892513dac2b9565be22
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S . F O R M A L _ V E C T O R S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2010-2011, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 ------------------------------------------------------------------------------
28 with Ada.Containers.Generic_Array_Sort;
29 with System; use type System.Address;
31 package body Ada.Containers.Formal_Vectors is
33 type Int is range System.Min_Int .. System.Max_Int;
34 type UInt is mod System.Max_Binary_Modulus;
36 function Get_Element
37 (Container : Vector;
38 Position : Count_Type) return Element_Type;
40 ---------
41 -- "&" --
42 ---------
44 function "&" (Left, Right : Vector) return Vector is
45 LN : constant Count_Type := Length (Left);
46 RN : constant Count_Type := Length (Right);
48 begin
49 if LN = 0 then
50 if RN = 0 then
51 return Empty_Vector;
52 end if;
54 declare
55 E : constant Elements_Array (1 .. Length (Right)) :=
56 Right.Elements (1 .. RN);
57 begin
58 return (Length (Right), E, Last => Right.Last, others => <>);
59 end;
60 end if;
62 if RN = 0 then
63 declare
64 E : constant Elements_Array (1 .. Length (Left)) :=
65 Left.Elements (1 .. LN);
66 begin
67 return (Length (Left), E, Last => Left.Last, others => <>);
68 end;
69 end if;
71 declare
72 N : constant Int'Base := Int (LN) + Int (RN);
73 Last_As_Int : Int'Base;
75 begin
76 if Int (No_Index) > Int'Last - N then
77 raise Constraint_Error with "new length is out of range";
78 end if;
80 Last_As_Int := Int (No_Index) + N;
82 if Last_As_Int > Int (Index_Type'Last) then
83 raise Constraint_Error with "new length is out of range";
84 end if;
86 -- TODO: should check whether length > max capacity (cnt_t'last) ???
88 declare
89 Last : constant Index_Type := Index_Type (Last_As_Int);
91 LE : constant Elements_Array (1 .. LN) := Left.Elements (1 .. LN);
92 RE : Elements_Array renames Right.Elements (1 .. RN);
94 Capacity : constant Count_Type := Length (Left) + Length (Right);
96 begin
97 return (Capacity, LE & RE, Last => Last, others => <>);
98 end;
99 end;
100 end "&";
102 function "&" (Left : Vector; Right : Element_Type) return Vector is
103 LN : constant Count_Type := Length (Left);
104 Last_As_Int : Int'Base;
106 begin
107 if LN = 0 then
108 return (1, (1 .. 1 => Right), Index_Type'First, others => <>);
109 end if;
111 if Int (Index_Type'First) > Int'Last - Int (LN) then
112 raise Constraint_Error with "new length is out of range";
113 end if;
115 Last_As_Int := Int (Index_Type'First) + Int (LN);
117 if Last_As_Int > Int (Index_Type'Last) then
118 raise Constraint_Error with "new length is out of range";
119 end if;
121 declare
122 Last : constant Index_Type := Index_Type (Last_As_Int);
123 LE : constant Elements_Array (1 .. LN) := Left.Elements (1 .. LN);
125 Capacity : constant Count_Type := Length (Left) + 1;
127 begin
128 return (Capacity, LE & Right, Last => Last, others => <>);
129 end;
130 end "&";
132 function "&" (Left : Element_Type; Right : Vector) return Vector is
133 RN : constant Count_Type := Length (Right);
134 Last_As_Int : Int'Base;
136 begin
137 if RN = 0 then
138 return (1, (1 .. 1 => Left),
139 Index_Type'First, others => <>);
140 end if;
142 if Int (Index_Type'First) > Int'Last - Int (RN) then
143 raise Constraint_Error with "new length is out of range";
144 end if;
146 Last_As_Int := Int (Index_Type'First) + Int (RN);
148 if Last_As_Int > Int (Index_Type'Last) then
149 raise Constraint_Error with "new length is out of range";
150 end if;
152 declare
153 Last : constant Index_Type := Index_Type (Last_As_Int);
154 RE : Elements_Array renames Right.Elements (1 .. RN);
155 Capacity : constant Count_Type := 1 + Length (Right);
156 begin
157 return (Capacity, Left & RE, Last => Last, others => <>);
158 end;
159 end "&";
161 function "&" (Left, Right : Element_Type) return Vector is
162 begin
163 if Index_Type'First >= Index_Type'Last then
164 raise Constraint_Error with "new length is out of range";
165 end if;
167 declare
168 Last : constant Index_Type := Index_Type'First + 1;
169 begin
170 return (2, (Left, Right), Last => Last, others => <>);
171 end;
172 end "&";
174 ---------
175 -- "=" --
176 ---------
178 function "=" (Left, Right : Vector) return Boolean is
179 begin
180 if Left'Address = Right'Address then
181 return True;
182 end if;
184 if Length (Left) /= Length (Right) then
185 return False;
186 end if;
188 for J in Count_Type range 1 .. Length (Left) loop
189 if Get_Element (Left, J) /= Get_Element (Right, J) then
190 return False;
191 end if;
192 end loop;
194 return True;
195 end "=";
197 ------------
198 -- Append --
199 ------------
201 procedure Append (Container : in out Vector; New_Item : Vector) is
202 begin
203 if Is_Empty (New_Item) then
204 return;
205 end if;
207 if Container.Last = Index_Type'Last then
208 raise Constraint_Error with "vector is already at its maximum length";
209 end if;
211 Insert (Container, Container.Last + 1, New_Item);
212 end Append;
214 procedure Append
215 (Container : in out Vector;
216 New_Item : Element_Type;
217 Count : Count_Type := 1)
219 begin
220 if Count = 0 then
221 return;
222 end if;
224 if Container.Last = Index_Type'Last then
225 raise Constraint_Error with "vector is already at its maximum length";
226 end if;
228 -- TODO: should check whether length > max capacity (cnt_t'last) ???
230 Insert (Container, Container.Last + 1, New_Item, Count);
231 end Append;
233 ------------
234 -- Assign --
235 ------------
237 procedure Assign (Target : in out Vector; Source : Vector) is
238 LS : constant Count_Type := Length (Source);
240 begin
241 if Target'Address = Source'Address then
242 return;
243 end if;
245 if Target.Capacity < LS then
246 raise Constraint_Error;
247 end if;
249 Target.Clear;
251 Target.Elements (1 .. LS) := Source.Elements (1 .. LS);
252 Target.Last := Source.Last;
253 end Assign;
255 --------------
256 -- Capacity --
257 --------------
259 function Capacity (Container : Vector) return Capacity_Subtype is
260 begin
261 return Container.Elements'Length;
262 end Capacity;
264 -----------
265 -- Clear --
266 -----------
268 procedure Clear (Container : in out Vector) is
269 begin
270 if Container.Busy > 0 then
271 raise Program_Error with
272 "attempt to tamper with elements (vector is busy)";
273 end if;
275 Container.Last := No_Index;
276 end Clear;
278 --------------
279 -- Contains --
280 --------------
282 function Contains
283 (Container : Vector;
284 Item : Element_Type) return Boolean
286 begin
287 return Find_Index (Container, Item) /= No_Index;
288 end Contains;
290 ----------
291 -- Copy --
292 ----------
294 function Copy
295 (Source : Vector;
296 Capacity : Capacity_Subtype := 0) return Vector
298 LS : constant Count_Type := Length (Source);
299 C : Capacity_Subtype;
301 begin
302 if Capacity = 0 then
303 C := LS;
304 elsif Capacity >= LS then
305 C := Capacity;
306 else
307 raise Constraint_Error;
308 end if;
310 return Target : Vector (C) do
311 Target.Elements (1 .. LS) := Source.Elements (1 .. LS);
312 Target.Last := Source.Last;
313 end return;
314 end Copy;
316 ------------
317 -- Delete --
318 ------------
320 procedure Delete
321 (Container : in out Vector;
322 Index : Extended_Index;
323 Count : Count_Type := 1)
325 begin
326 if Index < Index_Type'First then
327 raise Constraint_Error with "Index is out of range (too small)";
328 end if;
330 if Index > Container.Last then
331 if Index > Container.Last + 1 then
332 raise Constraint_Error with "Index is out of range (too large)";
333 end if;
335 return;
336 end if;
338 if Count = 0 then
339 return;
340 end if;
342 if Container.Busy > 0 then
343 raise Program_Error with
344 "attempt to tamper with elements (vector is busy)";
345 end if;
347 declare
348 I_As_Int : constant Int := Int (Index);
349 Old_Last_As_Int : constant Int := Index_Type'Pos (Container.Last);
351 Count1 : constant Int'Base := Count_Type'Pos (Count);
352 Count2 : constant Int'Base := Old_Last_As_Int - I_As_Int + 1;
353 N : constant Int'Base := Int'Min (Count1, Count2);
355 J_As_Int : constant Int'Base := I_As_Int + N;
357 begin
358 if J_As_Int > Old_Last_As_Int then
359 Container.Last := Index - 1;
361 else
362 declare
363 EA : Elements_Array renames Container.Elements;
365 II : constant Int'Base := I_As_Int - Int (No_Index);
366 I : constant Count_Type := Count_Type (II);
368 JJ : constant Int'Base := J_As_Int - Int (No_Index);
369 J : constant Count_Type := Count_Type (JJ);
371 New_Last_As_Int : constant Int'Base := Old_Last_As_Int - N;
372 New_Last : constant Index_Type :=
373 Index_Type (New_Last_As_Int);
375 KK : constant Int := New_Last_As_Int - Int (No_Index);
376 K : constant Count_Type := Count_Type (KK);
378 begin
379 EA (I .. K) := EA (J .. Length (Container));
380 Container.Last := New_Last;
381 end;
382 end if;
383 end;
384 end Delete;
386 procedure Delete
387 (Container : in out Vector;
388 Position : in out Cursor;
389 Count : Count_Type := 1)
391 begin
392 if not Position.Valid then
393 raise Constraint_Error with "Position cursor has no element";
394 end if;
396 if Position.Index > Container.Last then
397 raise Program_Error with "Position index is out of range";
398 end if;
400 Delete (Container, Position.Index, Count);
401 Position := No_Element;
402 end Delete;
404 ------------------
405 -- Delete_First --
406 ------------------
408 procedure Delete_First
409 (Container : in out Vector;
410 Count : Count_Type := 1)
412 begin
413 if Count = 0 then
414 return;
415 end if;
417 if Count >= Length (Container) then
418 Clear (Container);
419 return;
420 end if;
422 Delete (Container, Index_Type'First, Count);
423 end Delete_First;
425 -----------------
426 -- Delete_Last --
427 -----------------
429 procedure Delete_Last
430 (Container : in out Vector;
431 Count : Count_Type := 1)
433 Index : Int'Base;
435 begin
436 if Count = 0 then
437 return;
438 end if;
440 if Container.Busy > 0 then
441 raise Program_Error with
442 "attempt to tamper with elements (vector is busy)";
443 end if;
445 Index := Int'Base (Container.Last) - Int'Base (Count);
447 if Index < Index_Type'Pos (Index_Type'First) then
448 Container.Last := No_Index;
449 else
450 Container.Last := Index_Type (Index);
451 end if;
452 end Delete_Last;
454 -------------
455 -- Element --
456 -------------
458 function Element
459 (Container : Vector;
460 Index : Index_Type) return Element_Type
462 begin
463 if Index > Container.Last then
464 raise Constraint_Error with "Index is out of range";
465 end if;
467 declare
468 II : constant Int'Base := Int (Index) - Int (No_Index);
469 I : constant Count_Type := Count_Type (II);
470 begin
471 return Get_Element (Container, I);
472 end;
473 end Element;
475 function Element
476 (Container : Vector;
477 Position : Cursor) return Element_Type
479 Lst : constant Index_Type := Last_Index (Container);
481 begin
482 if not Position.Valid then
483 raise Constraint_Error with "Position cursor has no element";
484 end if;
486 if Position.Index > Lst then
487 raise Constraint_Error with "Position cursor is out of range";
488 end if;
490 declare
491 II : constant Int'Base := Int (Position.Index) - Int (No_Index);
492 I : constant Count_Type := Count_Type (II);
493 begin
494 return Get_Element (Container, I);
495 end;
496 end Element;
498 ----------
499 -- Find --
500 ----------
502 function Find
503 (Container : Vector;
504 Item : Element_Type;
505 Position : Cursor := No_Element) return Cursor
507 K : Count_Type;
508 Last : constant Index_Type := Last_Index (Container);
510 begin
511 if Position.Valid then
512 if Position.Index > Last_Index (Container) then
513 raise Program_Error with "Position index is out of range";
514 end if;
515 end if;
517 K := Count_Type (Int (Position.Index) - Int (No_Index));
519 for J in Position.Index .. Last loop
520 if Get_Element (Container, K) = Item then
521 return Cursor'(Index => J, others => <>);
522 end if;
524 K := K + 1;
525 end loop;
527 return No_Element;
528 end Find;
530 ----------------
531 -- Find_Index --
532 ----------------
534 function Find_Index
535 (Container : Vector;
536 Item : Element_Type;
537 Index : Index_Type := Index_Type'First) return Extended_Index
539 K : Count_Type;
540 Last : constant Index_Type := Last_Index (Container);
542 begin
543 K := Count_Type (Int (Index) - Int (No_Index));
544 for Indx in Index .. Last loop
545 if Get_Element (Container, K) = Item then
546 return Indx;
547 end if;
549 K := K + 1;
550 end loop;
552 return No_Index;
553 end Find_Index;
555 -----------
556 -- First --
557 -----------
559 function First (Container : Vector) return Cursor is
560 begin
561 if Is_Empty (Container) then
562 return No_Element;
563 end if;
565 return (True, Index_Type'First);
566 end First;
568 -------------------
569 -- First_Element --
570 -------------------
572 function First_Element (Container : Vector) return Element_Type is
573 begin
574 if Is_Empty (Container) then
575 raise Constraint_Error with "Container is empty";
576 end if;
578 return Get_Element (Container, 1);
579 end First_Element;
581 -----------------
582 -- First_Index --
583 -----------------
585 function First_Index (Container : Vector) return Index_Type is
586 pragma Unreferenced (Container);
587 begin
588 return Index_Type'First;
589 end First_Index;
591 ---------------------
592 -- Generic_Sorting --
593 ---------------------
595 package body Generic_Sorting is
597 ---------------
598 -- Is_Sorted --
599 ---------------
601 function Is_Sorted (Container : Vector) return Boolean is
602 Last : constant Index_Type := Last_Index (Container);
604 begin
605 if Container.Last <= Last then
606 return True;
607 end if;
609 declare
610 L : constant Capacity_Subtype := Length (Container);
611 begin
612 for J in Count_Type range 1 .. L - 1 loop
613 if Get_Element (Container, J + 1) <
614 Get_Element (Container, J)
615 then
616 return False;
617 end if;
618 end loop;
619 end;
621 return True;
622 end Is_Sorted;
624 -----------
625 -- Merge --
626 -----------
628 procedure Merge (Target, Source : in out Vector) is
629 begin
630 declare
631 TA : Elements_Array renames Target.Elements;
632 SA : Elements_Array renames Source.Elements;
634 I, J : Count_Type;
636 begin
637 -- ???
638 -- if Target.Last < Index_Type'First then
639 -- Move (Target => Target, Source => Source);
640 -- return;
641 -- end if;
643 if Target'Address = Source'Address then
644 return;
645 end if;
647 if Source.Last < Index_Type'First then
648 return;
649 end if;
651 -- I think we're missing this check in a-convec.adb... ???
653 if Target.Busy > 0 then
654 raise Program_Error with
655 "attempt to tamper with elements (vector is busy)";
656 end if;
658 if Source.Busy > 0 then
659 raise Program_Error with
660 "attempt to tamper with elements (vector is busy)";
661 end if;
663 I := Length (Target);
664 Target.Set_Length (I + Length (Source));
666 J := Length (Target);
667 while not Source.Is_Empty loop
668 pragma Assert (Length (Source) <= 1
669 or else not (SA (Length (Source)) <
670 SA (Length (Source) - 1)));
672 if I = 0 then
673 TA (1 .. J) := SA (1 .. Length (Source));
674 Source.Last := No_Index;
675 return;
676 end if;
678 pragma Assert (I <= 1 or else not (TA (I) < TA (I - 1)));
680 if SA (Length (Source)) < TA (I) then
681 TA (J) := TA (I);
682 I := I - 1;
684 else
685 TA (J) := SA (Length (Source));
686 Source.Last := Source.Last - 1;
687 end if;
689 J := J - 1;
690 end loop;
691 end;
692 end Merge;
694 ----------
695 -- Sort --
696 ----------
698 procedure Sort (Container : in out Vector)
700 procedure Sort is
701 new Generic_Array_Sort
702 (Index_Type => Count_Type,
703 Element_Type => Element_Type,
704 Array_Type => Elements_Array,
705 "<" => "<");
707 begin
708 if Container.Last <= Index_Type'First then
709 return;
710 end if;
712 if Container.Lock > 0 then
713 raise Program_Error with
714 "attempt to tamper with cursors (vector is locked)";
715 end if;
717 Sort (Container.Elements (1 .. Length (Container)));
718 end Sort;
720 end Generic_Sorting;
722 -----------------
723 -- Get_Element --
724 -----------------
726 function Get_Element
727 (Container : Vector;
728 Position : Count_Type) return Element_Type
730 begin
731 return Container.Elements (Position);
732 end Get_Element;
734 -----------------
735 -- Has_Element --
736 -----------------
738 function Has_Element
739 (Container : Vector;
740 Position : Cursor) return Boolean
742 begin
743 if not Position.Valid then
744 return False;
745 else
746 return Position.Index <= Last_Index (Container);
747 end if;
748 end Has_Element;
750 ------------
751 -- Insert --
752 ------------
754 procedure Insert
755 (Container : in out Vector;
756 Before : Extended_Index;
757 New_Item : Element_Type;
758 Count : Count_Type := 1)
760 N : constant Int := Count_Type'Pos (Count);
762 First : constant Int := Int (Index_Type'First);
763 New_Last_As_Int : Int'Base;
764 New_Last : Index_Type;
765 New_Length : UInt;
766 Max_Length : constant UInt := UInt (Container.Capacity);
768 begin
769 if Before < Index_Type'First then
770 raise Constraint_Error with
771 "Before index is out of range (too small)";
772 end if;
774 if Before > Container.Last
775 and then Before > Container.Last + 1
776 then
777 raise Constraint_Error with
778 "Before index is out of range (too large)";
779 end if;
781 if Count = 0 then
782 return;
783 end if;
785 declare
786 Old_Last_As_Int : constant Int := Int (Container.Last);
788 begin
789 if Old_Last_As_Int > Int'Last - N then
790 raise Constraint_Error with "new length is out of range";
791 end if;
793 New_Last_As_Int := Old_Last_As_Int + N;
795 if New_Last_As_Int > Int (Index_Type'Last) then
796 raise Constraint_Error with "new length is out of range";
797 end if;
799 New_Length := UInt (New_Last_As_Int - First + Int'(1));
801 if New_Length > Max_Length then
802 raise Constraint_Error with "new length is out of range";
803 end if;
805 New_Last := Index_Type (New_Last_As_Int);
807 -- Resolve issue of capacity vs. max index ???
808 end;
810 if Container.Busy > 0 then
811 raise Program_Error with
812 "attempt to tamper with elements (vector is busy)";
813 end if;
815 declare
816 EA : Elements_Array renames Container.Elements;
818 BB : constant Int'Base := Int (Before) - Int (No_Index);
819 B : constant Count_Type := Count_Type (BB);
821 LL : constant Int'Base := New_Last_As_Int - Int (No_Index);
822 L : constant Count_Type := Count_Type (LL);
824 begin
825 if Before <= Container.Last then
826 declare
827 II : constant Int'Base := BB + N;
828 I : constant Count_Type := Count_Type (II);
829 begin
830 EA (I .. L) := EA (B .. Length (Container));
831 EA (B .. I - 1) := (others => New_Item);
832 end;
834 else
835 EA (B .. L) := (others => New_Item);
836 end if;
837 end;
839 Container.Last := New_Last;
840 end Insert;
842 procedure Insert
843 (Container : in out Vector;
844 Before : Extended_Index;
845 New_Item : Vector)
847 N : constant Count_Type := Length (New_Item);
849 begin
850 if Before < Index_Type'First then
851 raise Constraint_Error with
852 "Before index is out of range (too small)";
853 end if;
855 if Before > Container.Last
856 and then Before > Container.Last + 1
857 then
858 raise Constraint_Error with
859 "Before index is out of range (too large)";
860 end if;
862 if N = 0 then
863 return;
864 end if;
866 Insert_Space (Container, Before, Count => N);
868 declare
869 Dst_Last_As_Int : constant Int'Base :=
870 Int (Before) + Int (N) - 1 - Int (No_Index);
872 Dst_Last : constant Count_Type := Count_Type (Dst_Last_As_Int);
874 BB : constant Int'Base := Int (Before) - Int (No_Index);
875 B : constant Count_Type := Count_Type (BB);
877 begin
878 if Container'Address /= New_Item'Address then
879 Container.Elements (B .. Dst_Last) := New_Item.Elements (1 .. N);
880 return;
881 end if;
883 declare
884 Src : Elements_Array renames Container.Elements (1 .. B - 1);
886 Index_As_Int : constant Int'Base := BB + Src'Length - 1;
888 Index : constant Count_Type := Count_Type (Index_As_Int);
890 Dst : Elements_Array renames Container.Elements (B .. Index);
892 begin
893 Dst := Src;
894 end;
896 if Dst_Last = Length (Container) then
897 return;
898 end if;
900 declare
901 Src : Elements_Array renames
902 Container.Elements (Dst_Last + 1 .. Length (Container));
904 Index_As_Int : constant Int'Base :=
905 Dst_Last_As_Int - Src'Length + 1;
907 Index : constant Count_Type := Count_Type (Index_As_Int);
909 Dst : Elements_Array renames
910 Container.Elements (Index .. Dst_Last);
912 begin
913 Dst := Src;
914 end;
915 end;
916 end Insert;
918 procedure Insert
919 (Container : in out Vector;
920 Before : Cursor;
921 New_Item : Vector)
923 Index : Index_Type'Base;
925 begin
926 if Is_Empty (New_Item) then
927 return;
928 end if;
930 if not Before.Valid
931 or else Before.Index > Container.Last
932 then
933 if Container.Last = Index_Type'Last then
934 raise Constraint_Error with
935 "vector is already at its maximum length";
936 end if;
938 Index := Container.Last + 1;
940 else
941 Index := Before.Index;
942 end if;
944 Insert (Container, Index, New_Item);
945 end Insert;
947 procedure Insert
948 (Container : in out Vector;
949 Before : Cursor;
950 New_Item : Vector;
951 Position : out Cursor)
953 Index : Index_Type'Base;
955 begin
956 if Is_Empty (New_Item) then
957 if not Before.Valid
958 or else Before.Index > Container.Last
959 then
960 Position := No_Element;
961 else
962 Position := (True, Before.Index);
963 end if;
965 return;
966 end if;
968 if not Before.Valid
969 or else Before.Index > Container.Last
970 then
971 if Container.Last = Index_Type'Last then
972 raise Constraint_Error with
973 "vector is already at its maximum length";
974 end if;
976 Index := Container.Last + 1;
978 else
979 Index := Before.Index;
980 end if;
982 Insert (Container, Index, New_Item);
984 Position := Cursor'(True, Index);
985 end Insert;
987 procedure Insert
988 (Container : in out Vector;
989 Before : Cursor;
990 New_Item : Element_Type;
991 Count : Count_Type := 1)
993 Index : Index_Type'Base;
995 begin
996 if Count = 0 then
997 return;
998 end if;
1000 if not Before.Valid
1001 or else Before.Index > Container.Last
1002 then
1003 if Container.Last = Index_Type'Last then
1004 raise Constraint_Error with
1005 "vector is already at its maximum length";
1006 end if;
1008 Index := Container.Last + 1;
1010 else
1011 Index := Before.Index;
1012 end if;
1014 Insert (Container, Index, New_Item, Count);
1015 end Insert;
1017 procedure Insert
1018 (Container : in out Vector;
1019 Before : Cursor;
1020 New_Item : Element_Type;
1021 Position : out Cursor;
1022 Count : Count_Type := 1)
1024 Index : Index_Type'Base;
1026 begin
1027 if Count = 0 then
1028 if not Before.Valid
1029 or else Before.Index > Container.Last
1030 then
1031 Position := No_Element;
1032 else
1033 Position := (True, Before.Index);
1034 end if;
1036 return;
1037 end if;
1039 if not Before.Valid
1040 or else Before.Index > Container.Last
1041 then
1042 if Container.Last = Index_Type'Last then
1043 raise Constraint_Error with
1044 "vector is already at its maximum length";
1045 end if;
1047 Index := Container.Last + 1;
1049 else
1050 Index := Before.Index;
1051 end if;
1053 Insert (Container, Index, New_Item, Count);
1055 Position := Cursor'(True, Index);
1056 end Insert;
1058 procedure Insert
1059 (Container : in out Vector;
1060 Before : Extended_Index;
1061 Count : Count_Type := 1)
1063 New_Item : Element_Type; -- Default-initialized value
1064 pragma Warnings (Off, New_Item);
1066 begin
1067 Insert (Container, Before, New_Item, Count);
1068 end Insert;
1070 procedure Insert
1071 (Container : in out Vector;
1072 Before : Cursor;
1073 Position : out Cursor;
1074 Count : Count_Type := 1)
1076 New_Item : Element_Type; -- Default-initialized value
1077 pragma Warnings (Off, New_Item);
1078 begin
1079 Insert (Container, Before, New_Item, Position, Count);
1080 end Insert;
1082 ------------------
1083 -- Insert_Space --
1084 ------------------
1086 procedure Insert_Space
1087 (Container : in out Vector;
1088 Before : Extended_Index;
1089 Count : Count_Type := 1)
1091 N : constant Int := Count_Type'Pos (Count);
1093 First : constant Int := Int (Index_Type'First);
1094 New_Last_As_Int : Int'Base;
1095 New_Last : Index_Type;
1096 New_Length : UInt;
1097 Max_Length : constant UInt := UInt (Count_Type'Last);
1099 begin
1100 if Before < Index_Type'First then
1101 raise Constraint_Error with
1102 "Before index is out of range (too small)";
1103 end if;
1105 if Before > Container.Last
1106 and then Before > Container.Last + 1
1107 then
1108 raise Constraint_Error with
1109 "Before index is out of range (too large)";
1110 end if;
1112 if Count = 0 then
1113 return;
1114 end if;
1116 declare
1117 Old_Last_As_Int : constant Int := Int (Container.Last);
1119 begin
1120 if Old_Last_As_Int > Int'Last - N then
1121 raise Constraint_Error with "new length is out of range";
1122 end if;
1124 New_Last_As_Int := Old_Last_As_Int + N;
1126 if New_Last_As_Int > Int (Index_Type'Last) then
1127 raise Constraint_Error with "new length is out of range";
1128 end if;
1130 New_Length := UInt (New_Last_As_Int - First + Int'(1));
1132 if New_Length > Max_Length then
1133 raise Constraint_Error with "new length is out of range";
1134 end if;
1136 New_Last := Index_Type (New_Last_As_Int);
1138 -- Resolve issue of capacity vs. max index ???
1139 end;
1141 if Container.Busy > 0 then
1142 raise Program_Error with
1143 "attempt to tamper with elements (vector is busy)";
1144 end if;
1146 declare
1147 EA : Elements_Array renames Container.Elements;
1149 BB : constant Int'Base := Int (Before) - Int (No_Index);
1150 B : constant Count_Type := Count_Type (BB);
1152 LL : constant Int'Base := New_Last_As_Int - Int (No_Index);
1153 L : constant Count_Type := Count_Type (LL);
1155 begin
1156 if Before <= Container.Last then
1157 declare
1158 II : constant Int'Base := BB + N;
1159 I : constant Count_Type := Count_Type (II);
1160 begin
1161 EA (I .. L) := EA (B .. Length (Container));
1162 end;
1163 end if;
1164 end;
1166 Container.Last := New_Last;
1167 end Insert_Space;
1169 procedure Insert_Space
1170 (Container : in out Vector;
1171 Before : Cursor;
1172 Position : out Cursor;
1173 Count : Count_Type := 1)
1175 Index : Index_Type'Base;
1177 begin
1178 if Count = 0 then
1179 if not Before.Valid
1180 or else Before.Index > Container.Last
1181 then
1182 Position := No_Element;
1183 else
1184 Position := (True, Before.Index);
1185 end if;
1187 return;
1188 end if;
1190 if not Before.Valid
1191 or else Before.Index > Container.Last
1192 then
1193 if Container.Last = Index_Type'Last then
1194 raise Constraint_Error with
1195 "vector is already at its maximum length";
1196 end if;
1198 Index := Container.Last + 1;
1200 else
1201 Index := Before.Index;
1202 end if;
1204 Insert_Space (Container, Index, Count => Count);
1206 Position := Cursor'(True, Index);
1207 end Insert_Space;
1209 --------------
1210 -- Is_Empty --
1211 --------------
1213 function Is_Empty (Container : Vector) return Boolean is
1214 begin
1215 return Last_Index (Container) < Index_Type'First;
1216 end Is_Empty;
1218 -------------
1219 -- Iterate --
1220 -------------
1222 procedure Iterate
1223 (Container : Vector;
1224 Process :
1225 not null access procedure (Container : Vector; Position : Cursor))
1227 V : Vector renames Container'Unrestricted_Access.all;
1228 B : Natural renames V.Busy;
1230 begin
1231 B := B + 1;
1233 begin
1234 for Indx in Index_Type'First .. Last_Index (Container) loop
1235 Process (Container, Cursor'(True, Indx));
1236 end loop;
1237 exception
1238 when others =>
1239 B := B - 1;
1240 raise;
1241 end;
1243 B := B - 1;
1244 end Iterate;
1246 ----------
1247 -- Last --
1248 ----------
1250 function Last (Container : Vector) return Cursor is
1251 begin
1252 if Is_Empty (Container) then
1253 return No_Element;
1254 end if;
1256 return (True, Last_Index (Container));
1257 end Last;
1259 ------------------
1260 -- Last_Element --
1261 ------------------
1263 function Last_Element (Container : Vector) return Element_Type is
1264 begin
1265 if Is_Empty (Container) then
1266 raise Constraint_Error with "Container is empty";
1267 end if;
1269 return Get_Element (Container, Length (Container));
1270 end Last_Element;
1272 ----------------
1273 -- Last_Index --
1274 ----------------
1276 function Last_Index (Container : Vector) return Extended_Index is
1277 begin
1278 return Container.Last;
1279 end Last_Index;
1281 ------------
1282 -- Length --
1283 ------------
1285 function Length (Container : Vector) return Capacity_Subtype is
1286 L : constant Int := Int (Last_Index (Container));
1287 F : constant Int := Int (Index_Type'First);
1288 N : constant Int'Base := L - F + 1;
1290 begin
1291 return Capacity_Subtype (N);
1292 end Length;
1294 ----------
1295 -- Left --
1296 ----------
1298 function Left (Container : Vector; Position : Cursor) return Vector is
1299 C : Vector (Container.Capacity) := Copy (Container, Container.Capacity);
1301 begin
1302 if Position = No_Element then
1303 return C;
1304 end if;
1306 if not Has_Element (Container, Position) then
1307 raise Constraint_Error;
1308 end if;
1310 while C.Last /= Position.Index - 1 loop
1311 Delete_Last (C);
1312 end loop;
1313 return C;
1314 end Left;
1316 ----------
1317 -- Move --
1318 ----------
1320 procedure Move
1321 (Target : in out Vector;
1322 Source : in out Vector)
1324 N : constant Count_Type := Length (Source);
1326 begin
1327 if Target'Address = Source'Address then
1328 return;
1329 end if;
1331 if Target.Busy > 0 then
1332 raise Program_Error with
1333 "attempt to tamper with elements (Target is busy)";
1334 end if;
1336 if Source.Busy > 0 then
1337 raise Program_Error with
1338 "attempt to tamper with elements (Source is busy)";
1339 end if;
1341 if N > Target.Capacity then
1342 raise Constraint_Error with -- correct exception here???
1343 "length of Source is greater than capacity of Target";
1344 end if;
1346 -- We could also write this as a loop, and incrementally
1347 -- copy elements from source to target.
1349 Target.Last := No_Index; -- in case array assignment files
1350 Target.Elements (1 .. N) := Source.Elements (1 .. N);
1352 Target.Last := Source.Last;
1353 Source.Last := No_Index;
1354 end Move;
1356 ----------
1357 -- Next --
1358 ----------
1360 function Next (Container : Vector; Position : Cursor) return Cursor is
1361 begin
1362 if not Position.Valid then
1363 return No_Element;
1364 end if;
1366 if Position.Index < Last_Index (Container) then
1367 return (True, Position.Index + 1);
1368 end if;
1370 return No_Element;
1371 end Next;
1373 ----------
1374 -- Next --
1375 ----------
1377 procedure Next (Container : Vector; Position : in out Cursor) is
1378 begin
1379 if not Position.Valid then
1380 return;
1381 end if;
1383 if Position.Index < Last_Index (Container) then
1384 Position.Index := Position.Index + 1;
1385 else
1386 Position := No_Element;
1387 end if;
1388 end Next;
1390 -------------
1391 -- Prepend --
1392 -------------
1394 procedure Prepend (Container : in out Vector; New_Item : Vector) is
1395 begin
1396 Insert (Container, Index_Type'First, New_Item);
1397 end Prepend;
1399 procedure Prepend
1400 (Container : in out Vector;
1401 New_Item : Element_Type;
1402 Count : Count_Type := 1)
1404 begin
1405 Insert (Container,
1406 Index_Type'First,
1407 New_Item,
1408 Count);
1409 end Prepend;
1411 --------------
1412 -- Previous --
1413 --------------
1415 procedure Previous (Container : Vector; Position : in out Cursor) is
1416 begin
1417 if not Position.Valid then
1418 return;
1419 end if;
1421 if Position.Index > Index_Type'First and
1422 Position.Index <= Last_Index (Container) then
1423 Position.Index := Position.Index - 1;
1424 else
1425 Position := No_Element;
1426 end if;
1427 end Previous;
1429 function Previous (Container : Vector; Position : Cursor) return Cursor is
1430 begin
1431 if not Position.Valid then
1432 return No_Element;
1433 end if;
1435 if Position.Index > Index_Type'First and
1436 Position.Index <= Last_Index (Container) then
1437 return (True, Position.Index - 1);
1438 end if;
1440 return No_Element;
1441 end Previous;
1443 -------------------
1444 -- Query_Element --
1445 -------------------
1447 procedure Query_Element
1448 (Container : Vector;
1449 Index : Index_Type;
1450 Process : not null access procedure (Element : Element_Type))
1452 V : Vector renames Container'Unrestricted_Access.all;
1453 B : Natural renames V.Busy;
1454 L : Natural renames V.Lock;
1456 begin
1457 if Index > Last_Index (Container) then
1458 raise Constraint_Error with "Index is out of range";
1459 end if;
1461 B := B + 1;
1462 L := L + 1;
1464 declare
1465 II : constant Int'Base := Int (Index) - Int (No_Index);
1466 I : constant Count_Type := Count_Type (II);
1468 begin
1469 Process (Get_Element (V, I));
1470 exception
1471 when others =>
1472 L := L - 1;
1473 B := B - 1;
1474 raise;
1475 end;
1477 L := L - 1;
1478 B := B - 1;
1479 end Query_Element;
1481 procedure Query_Element
1482 (Container : Vector;
1483 Position : Cursor;
1484 Process : not null access procedure (Element : Element_Type))
1486 begin
1487 if not Position.Valid then
1488 raise Constraint_Error with "Position cursor has no element";
1489 end if;
1491 Query_Element (Container, Position.Index, Process);
1492 end Query_Element;
1494 ----------
1495 -- Read --
1496 ----------
1498 procedure Read
1499 (Stream : not null access Root_Stream_Type'Class;
1500 Container : out Vector)
1502 Length : Count_Type'Base;
1503 Last : Index_Type'Base := No_Index;
1505 begin
1506 Clear (Container);
1508 Count_Type'Base'Read (Stream, Length);
1510 if Length < 0 then
1511 raise Program_Error with "stream appears to be corrupt";
1512 end if;
1514 if Length > Container.Capacity then
1515 raise Storage_Error with "not enough capacity"; -- ???
1516 end if;
1518 for J in Count_Type range 1 .. Length loop
1519 Last := Last + 1;
1520 Element_Type'Read (Stream, Container.Elements (J));
1521 Container.Last := Last;
1522 end loop;
1523 end Read;
1525 procedure Read
1526 (Stream : not null access Root_Stream_Type'Class;
1527 Position : out Cursor)
1529 begin
1530 raise Program_Error with "attempt to stream vector cursor";
1531 end Read;
1533 ---------------------
1534 -- Replace_Element --
1535 ---------------------
1537 procedure Replace_Element
1538 (Container : in out Vector;
1539 Index : Index_Type;
1540 New_Item : Element_Type)
1542 begin
1543 if Index > Container.Last then
1544 raise Constraint_Error with "Index is out of range";
1545 end if;
1547 if Container.Lock > 0 then
1548 raise Program_Error with
1549 "attempt to tamper with cursors (vector is locked)";
1550 end if;
1552 declare
1553 II : constant Int'Base := Int (Index) - Int (No_Index);
1554 I : constant Count_Type := Count_Type (II);
1556 begin
1557 Container.Elements (I) := New_Item;
1558 end;
1559 end Replace_Element;
1561 procedure Replace_Element
1562 (Container : in out Vector;
1563 Position : Cursor;
1564 New_Item : Element_Type)
1566 begin
1567 if not Position.Valid then
1568 raise Constraint_Error with "Position cursor has no element";
1569 end if;
1571 if Position.Index > Container.Last then
1572 raise Constraint_Error with "Position cursor is out of range";
1573 end if;
1575 if Container.Lock > 0 then
1576 raise Program_Error with
1577 "attempt to tamper with cursors (vector is locked)";
1578 end if;
1580 declare
1581 II : constant Int'Base := Int (Position.Index) - Int (No_Index);
1582 I : constant Count_Type := Count_Type (II);
1583 begin
1584 Container.Elements (I) := New_Item;
1585 end;
1586 end Replace_Element;
1588 ----------------------
1589 -- Reserve_Capacity --
1590 ----------------------
1592 procedure Reserve_Capacity
1593 (Container : in out Vector;
1594 Capacity : Capacity_Subtype)
1596 begin
1597 if Capacity > Container.Capacity then
1598 raise Constraint_Error; -- ???
1599 end if;
1600 end Reserve_Capacity;
1602 ----------------------
1603 -- Reverse_Elements --
1604 ----------------------
1606 procedure Reverse_Elements (Container : in out Vector) is
1607 begin
1608 if Length (Container) <= 1 then
1609 return;
1610 end if;
1612 if Container.Lock > 0 then
1613 raise Program_Error with
1614 "attempt to tamper with cursors (vector is locked)";
1615 end if;
1617 declare
1618 I, J : Count_Type;
1619 E : Elements_Array renames Container.Elements;
1621 begin
1622 I := 1;
1623 J := Length (Container);
1624 while I < J loop
1625 declare
1626 EI : constant Element_Type := E (I);
1627 begin
1628 E (I) := E (J);
1629 E (J) := EI;
1630 end;
1632 I := I + 1;
1633 J := J - 1;
1634 end loop;
1635 end;
1636 end Reverse_Elements;
1638 ------------------
1639 -- Reverse_Find --
1640 ------------------
1642 function Reverse_Find
1643 (Container : Vector;
1644 Item : Element_Type;
1645 Position : Cursor := No_Element) return Cursor
1647 Last : Index_Type'Base;
1648 K : Count_Type;
1650 begin
1651 if not Position.Valid
1652 or else Position.Index > Last_Index (Container)
1653 then
1654 Last := Last_Index (Container);
1655 else
1656 Last := Position.Index;
1657 end if;
1659 K := Count_Type (Int (Last) - Int (No_Index));
1660 for Indx in reverse Index_Type'First .. Last loop
1661 if Get_Element (Container, K) = Item then
1662 return (True, Indx);
1663 end if;
1665 K := K - 1;
1666 end loop;
1668 return No_Element;
1669 end Reverse_Find;
1671 ------------------------
1672 -- Reverse_Find_Index --
1673 ------------------------
1675 function Reverse_Find_Index
1676 (Container : Vector;
1677 Item : Element_Type;
1678 Index : Index_Type := Index_Type'Last) return Extended_Index
1680 Last : Index_Type'Base;
1681 K : Count_Type;
1683 begin
1684 if Index > Last_Index (Container) then
1685 Last := Last_Index (Container);
1686 else
1687 Last := Index;
1688 end if;
1690 K := Count_Type (Int (Last) - Int (No_Index));
1691 for Indx in reverse Index_Type'First .. Last loop
1692 if Get_Element (Container, K) = Item then
1693 return Indx;
1694 end if;
1696 K := K - 1;
1697 end loop;
1699 return No_Index;
1700 end Reverse_Find_Index;
1702 ---------------------
1703 -- Reverse_Iterate --
1704 ---------------------
1706 procedure Reverse_Iterate
1707 (Container : Vector;
1708 Process : not null access procedure (Container : Vector;
1709 Position : Cursor))
1711 V : Vector renames Container'Unrestricted_Access.all;
1712 B : Natural renames V.Busy;
1714 begin
1715 B := B + 1;
1717 begin
1718 for Indx in reverse Index_Type'First .. Last_Index (Container) loop
1719 Process (Container, Cursor'(True, Indx));
1720 end loop;
1721 exception
1722 when others =>
1723 B := B - 1;
1724 raise;
1725 end;
1727 B := B - 1;
1728 end Reverse_Iterate;
1730 -----------
1731 -- Right --
1732 -----------
1734 function Right (Container : Vector; Position : Cursor) return Vector is
1735 C : Vector (Container.Capacity) := Copy (Container, Container.Capacity);
1737 begin
1738 if Position = No_Element then
1739 Clear (C);
1740 return C;
1741 end if;
1743 if not Has_Element (Container, Position) then
1744 raise Constraint_Error;
1745 end if;
1747 while C.Last /= Container.Last - Position.Index + 1 loop
1748 Delete_First (C);
1749 end loop;
1751 return C;
1752 end Right;
1754 ----------------
1755 -- Set_Length --
1756 ----------------
1758 procedure Set_Length
1759 (Container : in out Vector;
1760 Length : Capacity_Subtype)
1762 begin
1763 if Length = Formal_Vectors.Length (Container) then
1764 return;
1765 end if;
1767 if Container.Busy > 0 then
1768 raise Program_Error with
1769 "attempt to tamper with elements (vector is busy)";
1770 end if;
1772 if Length > Container.Capacity then
1773 raise Constraint_Error; -- ???
1774 end if;
1776 declare
1777 Last_As_Int : constant Int'Base :=
1778 Int (Index_Type'First) + Int (Length) - 1;
1779 begin
1780 Container.Last := Index_Type'Base (Last_As_Int);
1781 end;
1782 end Set_Length;
1784 ----------
1785 -- Swap --
1786 ----------
1788 procedure Swap (Container : in out Vector; I, J : Index_Type) is
1789 begin
1790 if I > Container.Last then
1791 raise Constraint_Error with "I index is out of range";
1792 end if;
1794 if J > Container.Last then
1795 raise Constraint_Error with "J index is out of range";
1796 end if;
1798 if I = J then
1799 return;
1800 end if;
1802 if Container.Lock > 0 then
1803 raise Program_Error with
1804 "attempt to tamper with cursors (vector is locked)";
1805 end if;
1807 declare
1808 II : constant Int'Base := Int (I) - Int (No_Index);
1809 JJ : constant Int'Base := Int (J) - Int (No_Index);
1811 EI : Element_Type renames Container.Elements (Count_Type (II));
1812 EJ : Element_Type renames Container.Elements (Count_Type (JJ));
1814 EI_Copy : constant Element_Type := EI;
1816 begin
1817 EI := EJ;
1818 EJ := EI_Copy;
1819 end;
1820 end Swap;
1822 procedure Swap (Container : in out Vector; I, J : Cursor) is
1823 begin
1824 if not I.Valid then
1825 raise Constraint_Error with "I cursor has no element";
1826 end if;
1828 if not J.Valid then
1829 raise Constraint_Error with "J cursor has no element";
1830 end if;
1832 Swap (Container, I.Index, J.Index);
1833 end Swap;
1835 ---------------
1836 -- To_Cursor --
1837 ---------------
1839 function To_Cursor
1840 (Container : Vector;
1841 Index : Extended_Index) return Cursor
1843 begin
1844 if Index not in Index_Type'First .. Last_Index (Container) then
1845 return No_Element;
1846 end if;
1848 return Cursor'(True, Index);
1849 end To_Cursor;
1851 --------------
1852 -- To_Index --
1853 --------------
1855 function To_Index (Position : Cursor) return Extended_Index is
1856 begin
1857 if not Position.Valid then
1858 return No_Index;
1859 end if;
1861 return Position.Index;
1862 end To_Index;
1864 ---------------
1865 -- To_Vector --
1866 ---------------
1868 function To_Vector (Length : Capacity_Subtype) return Vector is
1869 begin
1870 if Length = 0 then
1871 return Empty_Vector;
1872 end if;
1874 declare
1875 First : constant Int := Int (Index_Type'First);
1876 Last_As_Int : constant Int'Base := First + Int (Length) - 1;
1877 Last : Index_Type;
1879 begin
1880 if Last_As_Int > Index_Type'Pos (Index_Type'Last) then
1881 raise Constraint_Error with "Length is out of range"; -- ???
1882 end if;
1884 Last := Index_Type (Last_As_Int);
1886 return (Length, (others => <>), Last => Last,
1887 others => <>);
1888 end;
1889 end To_Vector;
1891 function To_Vector
1892 (New_Item : Element_Type;
1893 Length : Capacity_Subtype) return Vector
1895 begin
1896 if Length = 0 then
1897 return Empty_Vector;
1898 end if;
1900 declare
1901 First : constant Int := Int (Index_Type'First);
1902 Last_As_Int : constant Int'Base := First + Int (Length) - 1;
1903 Last : Index_Type;
1905 begin
1906 if Last_As_Int > Index_Type'Pos (Index_Type'Last) then
1907 raise Constraint_Error with "Length is out of range"; -- ???
1908 end if;
1910 Last := Index_Type (Last_As_Int);
1912 return (Length, (others => New_Item), Last => Last,
1913 others => <>);
1914 end;
1915 end To_Vector;
1917 --------------------
1918 -- Update_Element --
1919 --------------------
1921 procedure Update_Element
1922 (Container : in out Vector;
1923 Index : Index_Type;
1924 Process : not null access procedure (Element : in out Element_Type))
1926 B : Natural renames Container.Busy;
1927 L : Natural renames Container.Lock;
1929 begin
1930 if Index > Container.Last then
1931 raise Constraint_Error with "Index is out of range";
1932 end if;
1934 B := B + 1;
1935 L := L + 1;
1937 declare
1938 II : constant Int'Base := Int (Index) - Int (No_Index);
1939 I : constant Count_Type := Count_Type (II);
1941 begin
1942 Process (Container.Elements (I));
1943 exception
1944 when others =>
1945 L := L - 1;
1946 B := B - 1;
1947 raise;
1948 end;
1950 L := L - 1;
1951 B := B - 1;
1952 end Update_Element;
1954 procedure Update_Element
1955 (Container : in out Vector;
1956 Position : Cursor;
1957 Process : not null access procedure (Element : in out Element_Type))
1959 begin
1960 if not Position.Valid then
1961 raise Constraint_Error with "Position cursor has no element";
1962 end if;
1964 Update_Element (Container, Position.Index, Process);
1965 end Update_Element;
1967 -----------
1968 -- Write --
1969 -----------
1971 procedure Write
1972 (Stream : not null access Root_Stream_Type'Class;
1973 Container : Vector)
1975 begin
1976 Count_Type'Base'Write (Stream, Length (Container));
1978 for J in 1 .. Length (Container) loop
1979 Element_Type'Write (Stream, Container.Elements (J));
1980 end loop;
1981 end Write;
1983 procedure Write
1984 (Stream : not null access Root_Stream_Type'Class;
1985 Position : Cursor)
1987 begin
1988 raise Program_Error with "attempt to stream vector cursor";
1989 end Write;
1991 end Ada.Containers.Formal_Vectors;