annotate gcc/ada/libgnat/a-cofuve.ads @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT LIBRARY COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- ADA.CONTAINERS.FUNCTIONAL_VECTORS --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 2016-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- This specification is derived from the Ada Reference Manual for use with --
kono
parents:
diff changeset
12 -- GNAT. The copyright notice above, and the license provisions that follow --
kono
parents:
diff changeset
13 -- apply solely to the contents of the part following the private keyword. --
kono
parents:
diff changeset
14 -- --
kono
parents:
diff changeset
15 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
16 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
23 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
24 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
25 -- --
kono
parents:
diff changeset
26 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
27 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
29 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 pragma Ada_2012;
kono
parents:
diff changeset
33 private with Ada.Containers.Functional_Base;
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 generic
kono
parents:
diff changeset
36 type Index_Type is (<>);
kono
parents:
diff changeset
37 -- To avoid Constraint_Error being raised at run time, Index_Type'Base
kono
parents:
diff changeset
38 -- should have at least one more element at the low end than Index_Type.
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 type Element_Type (<>) is private;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
41 with function "=" (Left, Right : Element_Type) return Boolean is <>;
111
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 package Ada.Containers.Functional_Vectors with SPARK_Mode is
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 subtype Extended_Index is Index_Type'Base range
kono
parents:
diff changeset
46 Index_Type'Pred (Index_Type'First) .. Index_Type'Last;
kono
parents:
diff changeset
47 -- Index_Type with one more element at the low end of the range.
kono
parents:
diff changeset
48 -- This type is never used but it forces GNATprove to check that there is
kono
parents:
diff changeset
49 -- room for one more element at the low end of Index_Type.
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 type Sequence is private
kono
parents:
diff changeset
52 with Default_Initial_Condition => Length (Sequence) = 0,
kono
parents:
diff changeset
53 Iterable => (First => Iter_First,
kono
parents:
diff changeset
54 Has_Element => Iter_Has_Element,
kono
parents:
diff changeset
55 Next => Iter_Next,
kono
parents:
diff changeset
56 Element => Get);
kono
parents:
diff changeset
57 -- Sequences are empty when default initialized.
kono
parents:
diff changeset
58 -- Quantification over sequences can be done using the regular
kono
parents:
diff changeset
59 -- quantification over its range or directly on its elements with "for of".
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 -----------------------
kono
parents:
diff changeset
62 -- Basic operations --
kono
parents:
diff changeset
63 -----------------------
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 -- Sequences are axiomatized using Length and Get, providing respectively
kono
parents:
diff changeset
66 -- the length of a sequence and an accessor to its Nth element:
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 function Length (Container : Sequence) return Count_Type with
kono
parents:
diff changeset
69 -- Length of a sequence
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 Global => null,
kono
parents:
diff changeset
72 Post =>
kono
parents:
diff changeset
73 (Index_Type'Pos (Index_Type'First) - 1) + Length'Result <=
kono
parents:
diff changeset
74 Index_Type'Pos (Index_Type'Last);
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 function Get
kono
parents:
diff changeset
77 (Container : Sequence;
kono
parents:
diff changeset
78 Position : Extended_Index) return Element_Type
kono
parents:
diff changeset
79 -- Access the Element at position Position in Container
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 with
kono
parents:
diff changeset
82 Global => null,
kono
parents:
diff changeset
83 Pre => Position in Index_Type'First .. Last (Container);
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 function Last (Container : Sequence) return Extended_Index with
kono
parents:
diff changeset
86 -- Last index of a sequence
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 Global => null,
kono
parents:
diff changeset
89 Post =>
kono
parents:
diff changeset
90 Last'Result =
kono
parents:
diff changeset
91 Index_Type'Val ((Index_Type'Pos (Index_Type'First) - 1) +
kono
parents:
diff changeset
92 Length (Container));
kono
parents:
diff changeset
93 pragma Annotate (GNATprove, Inline_For_Proof, Last);
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 function First return Extended_Index is (Index_Type'First);
kono
parents:
diff changeset
96 -- First index of a sequence
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 ------------------------
kono
parents:
diff changeset
99 -- Property Functions --
kono
parents:
diff changeset
100 ------------------------
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 function "=" (Left : Sequence; Right : Sequence) return Boolean with
kono
parents:
diff changeset
103 -- Extensional equality over sequences
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 Global => null,
kono
parents:
diff changeset
106 Post =>
kono
parents:
diff changeset
107 "="'Result =
kono
parents:
diff changeset
108 (Length (Left) = Length (Right)
kono
parents:
diff changeset
109 and then (for all N in Index_Type'First .. Last (Left) =>
kono
parents:
diff changeset
110 Get (Left, N) = Get (Right, N)));
kono
parents:
diff changeset
111 pragma Annotate (GNATprove, Inline_For_Proof, "=");
kono
parents:
diff changeset
112
kono
parents:
diff changeset
113 function "<" (Left : Sequence; Right : Sequence) return Boolean with
kono
parents:
diff changeset
114 -- Left is a strict subsequence of Right
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 Global => null,
kono
parents:
diff changeset
117 Post =>
kono
parents:
diff changeset
118 "<"'Result =
kono
parents:
diff changeset
119 (Length (Left) < Length (Right)
kono
parents:
diff changeset
120 and then (for all N in Index_Type'First .. Last (Left) =>
kono
parents:
diff changeset
121 Get (Left, N) = Get (Right, N)));
kono
parents:
diff changeset
122 pragma Annotate (GNATprove, Inline_For_Proof, "<");
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124 function "<=" (Left : Sequence; Right : Sequence) return Boolean with
kono
parents:
diff changeset
125 -- Left is a subsequence of Right
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 Global => null,
kono
parents:
diff changeset
128 Post =>
kono
parents:
diff changeset
129 "<="'Result =
kono
parents:
diff changeset
130 (Length (Left) <= Length (Right)
kono
parents:
diff changeset
131 and then (for all N in Index_Type'First .. Last (Left) =>
kono
parents:
diff changeset
132 Get (Left, N) = Get (Right, N)));
kono
parents:
diff changeset
133 pragma Annotate (GNATprove, Inline_For_Proof, "<=");
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 function Contains
kono
parents:
diff changeset
136 (Container : Sequence;
kono
parents:
diff changeset
137 Fst : Index_Type;
kono
parents:
diff changeset
138 Lst : Extended_Index;
kono
parents:
diff changeset
139 Item : Element_Type) return Boolean
kono
parents:
diff changeset
140 -- Returns True if Item occurs in the range from Fst to Lst of Container
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 with
kono
parents:
diff changeset
143 Global => null,
kono
parents:
diff changeset
144 Pre => Lst <= Last (Container),
kono
parents:
diff changeset
145 Post =>
kono
parents:
diff changeset
146 Contains'Result =
kono
parents:
diff changeset
147 (for some I in Fst .. Lst => Get (Container, I) = Item);
kono
parents:
diff changeset
148 pragma Annotate (GNATprove, Inline_For_Proof, Contains);
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 function Constant_Range
kono
parents:
diff changeset
151 (Container : Sequence;
kono
parents:
diff changeset
152 Fst : Index_Type;
kono
parents:
diff changeset
153 Lst : Extended_Index;
kono
parents:
diff changeset
154 Item : Element_Type) return Boolean
kono
parents:
diff changeset
155 -- Returns True if every element of the range from Fst to Lst of Container
kono
parents:
diff changeset
156 -- is equal to Item.
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 with
kono
parents:
diff changeset
159 Global => null,
kono
parents:
diff changeset
160 Pre => Lst <= Last (Container),
kono
parents:
diff changeset
161 Post =>
kono
parents:
diff changeset
162 Constant_Range'Result =
kono
parents:
diff changeset
163 (for all I in Fst .. Lst => Get (Container, I) = Item);
kono
parents:
diff changeset
164 pragma Annotate (GNATprove, Inline_For_Proof, Constant_Range);
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 function Equal_Except
kono
parents:
diff changeset
167 (Left : Sequence;
kono
parents:
diff changeset
168 Right : Sequence;
kono
parents:
diff changeset
169 Position : Index_Type) return Boolean
kono
parents:
diff changeset
170 -- Returns True is Left and Right are the same except at position Position
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 with
kono
parents:
diff changeset
173 Global => null,
kono
parents:
diff changeset
174 Pre => Position <= Last (Left),
kono
parents:
diff changeset
175 Post =>
kono
parents:
diff changeset
176 Equal_Except'Result =
kono
parents:
diff changeset
177 (Length (Left) = Length (Right)
kono
parents:
diff changeset
178 and then (for all I in Index_Type'First .. Last (Left) =>
kono
parents:
diff changeset
179 (if I /= Position then Get (Left, I) = Get (Right, I))));
kono
parents:
diff changeset
180 pragma Annotate (GNATprove, Inline_For_Proof, Equal_Except);
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 function Equal_Except
kono
parents:
diff changeset
183 (Left : Sequence;
kono
parents:
diff changeset
184 Right : Sequence;
kono
parents:
diff changeset
185 X : Index_Type;
kono
parents:
diff changeset
186 Y : Index_Type) return Boolean
kono
parents:
diff changeset
187 -- Returns True is Left and Right are the same except at positions X and Y
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 with
kono
parents:
diff changeset
190 Global => null,
kono
parents:
diff changeset
191 Pre => X <= Last (Left) and Y <= Last (Left),
kono
parents:
diff changeset
192 Post =>
kono
parents:
diff changeset
193 Equal_Except'Result =
kono
parents:
diff changeset
194 (Length (Left) = Length (Right)
kono
parents:
diff changeset
195 and then (for all I in Index_Type'First .. Last (Left) =>
kono
parents:
diff changeset
196 (if I /= X and I /= Y then
kono
parents:
diff changeset
197 Get (Left, I) = Get (Right, I))));
kono
parents:
diff changeset
198 pragma Annotate (GNATprove, Inline_For_Proof, Equal_Except);
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 function Range_Equal
kono
parents:
diff changeset
201 (Left : Sequence;
kono
parents:
diff changeset
202 Right : Sequence;
kono
parents:
diff changeset
203 Fst : Index_Type;
kono
parents:
diff changeset
204 Lst : Extended_Index) return Boolean
kono
parents:
diff changeset
205 -- Returns True if the ranges from Fst to Lst contain the same elements in
kono
parents:
diff changeset
206 -- Left and Right.
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 with
kono
parents:
diff changeset
209 Global => null,
kono
parents:
diff changeset
210 Pre => Lst <= Last (Left) and Lst <= Last (Right),
kono
parents:
diff changeset
211 Post =>
kono
parents:
diff changeset
212 Range_Equal'Result =
kono
parents:
diff changeset
213 (for all I in Fst .. Lst => Get (Left, I) = Get (Right, I));
kono
parents:
diff changeset
214 pragma Annotate (GNATprove, Inline_For_Proof, Range_Equal);
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 function Range_Shifted
kono
parents:
diff changeset
217 (Left : Sequence;
kono
parents:
diff changeset
218 Right : Sequence;
kono
parents:
diff changeset
219 Fst : Index_Type;
kono
parents:
diff changeset
220 Lst : Extended_Index;
kono
parents:
diff changeset
221 Offset : Count_Type'Base) return Boolean
kono
parents:
diff changeset
222 -- Returns True if the range from Fst to Lst in Left contains the same
kono
parents:
diff changeset
223 -- elements as the range from Fst + Offset to Lst + Offset in Right.
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 with
kono
parents:
diff changeset
226 Global => null,
kono
parents:
diff changeset
227 Pre =>
kono
parents:
diff changeset
228 Lst <= Last (Left)
kono
parents:
diff changeset
229 and then
kono
parents:
diff changeset
230 (if Offset < 0 then
kono
parents:
diff changeset
231 Index_Type'Pos (Index_Type'Base'First) - Offset <=
kono
parents:
diff changeset
232 Index_Type'Pos (Index_Type'First))
kono
parents:
diff changeset
233 and then
kono
parents:
diff changeset
234 (if Fst <= Lst then
kono
parents:
diff changeset
235 Offset in
kono
parents:
diff changeset
236 Index_Type'Pos (Index_Type'First) - Index_Type'Pos (Fst) ..
kono
parents:
diff changeset
237 (Index_Type'Pos (Index_Type'First) - 1) + Length (Right) -
kono
parents:
diff changeset
238 Index_Type'Pos (Lst)),
kono
parents:
diff changeset
239 Post =>
kono
parents:
diff changeset
240 Range_Shifted'Result =
kono
parents:
diff changeset
241 ((for all I in Fst .. Lst =>
kono
parents:
diff changeset
242 Get (Left, I) =
kono
parents:
diff changeset
243 Get (Right, Index_Type'Val (Index_Type'Pos (I) + Offset)))
kono
parents:
diff changeset
244 and
kono
parents:
diff changeset
245 (for all I in Index_Type'Val (Index_Type'Pos (Fst) + Offset) ..
kono
parents:
diff changeset
246 Index_Type'Val (Index_Type'Pos (Lst) + Offset)
kono
parents:
diff changeset
247 =>
kono
parents:
diff changeset
248 Get (Left, Index_Type'Val (Index_Type'Pos (I) - Offset)) =
kono
parents:
diff changeset
249 Get (Right, I)));
kono
parents:
diff changeset
250 pragma Annotate (GNATprove, Inline_For_Proof, Range_Shifted);
kono
parents:
diff changeset
251
kono
parents:
diff changeset
252 ----------------------------
kono
parents:
diff changeset
253 -- Construction Functions --
kono
parents:
diff changeset
254 ----------------------------
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 -- For better efficiency of both proofs and execution, avoid using
kono
parents:
diff changeset
257 -- construction functions in annotations and rather use property functions.
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 function Set
kono
parents:
diff changeset
260 (Container : Sequence;
kono
parents:
diff changeset
261 Position : Index_Type;
kono
parents:
diff changeset
262 New_Item : Element_Type) return Sequence
kono
parents:
diff changeset
263 -- Returns a new sequence which contains the same elements as Container
kono
parents:
diff changeset
264 -- except for the one at position Position which is replaced by New_Item.
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 with
kono
parents:
diff changeset
267 Global => null,
kono
parents:
diff changeset
268 Pre => Position in Index_Type'First .. Last (Container),
kono
parents:
diff changeset
269 Post =>
kono
parents:
diff changeset
270 Get (Set'Result, Position) = New_Item
kono
parents:
diff changeset
271 and then Equal_Except (Container, Set'Result, Position);
kono
parents:
diff changeset
272
kono
parents:
diff changeset
273 function Add (Container : Sequence; New_Item : Element_Type) return Sequence
kono
parents:
diff changeset
274 -- Returns a new sequence which contains the same elements as Container
kono
parents:
diff changeset
275 -- plus New_Item at the end.
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 with
kono
parents:
diff changeset
278 Global => null,
kono
parents:
diff changeset
279 Pre =>
kono
parents:
diff changeset
280 Length (Container) < Count_Type'Last
kono
parents:
diff changeset
281 and then Last (Container) < Index_Type'Last,
kono
parents:
diff changeset
282 Post =>
kono
parents:
diff changeset
283 Length (Add'Result) = Length (Container) + 1
kono
parents:
diff changeset
284 and then Get (Add'Result, Last (Add'Result)) = New_Item
kono
parents:
diff changeset
285 and then Container <= Add'Result;
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 function Add
kono
parents:
diff changeset
288 (Container : Sequence;
kono
parents:
diff changeset
289 Position : Index_Type;
kono
parents:
diff changeset
290 New_Item : Element_Type) return Sequence
kono
parents:
diff changeset
291 with
kono
parents:
diff changeset
292 -- Returns a new sequence which contains the same elements as Container
kono
parents:
diff changeset
293 -- except that New_Item has been inserted at position Position.
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 Global => null,
kono
parents:
diff changeset
296 Pre =>
kono
parents:
diff changeset
297 Length (Container) < Count_Type'Last
kono
parents:
diff changeset
298 and then Last (Container) < Index_Type'Last
kono
parents:
diff changeset
299 and then Position <= Extended_Index'Succ (Last (Container)),
kono
parents:
diff changeset
300 Post =>
kono
parents:
diff changeset
301 Length (Add'Result) = Length (Container) + 1
kono
parents:
diff changeset
302 and then Get (Add'Result, Position) = New_Item
kono
parents:
diff changeset
303 and then Range_Equal
kono
parents:
diff changeset
304 (Left => Container,
kono
parents:
diff changeset
305 Right => Add'Result,
kono
parents:
diff changeset
306 Fst => Index_Type'First,
kono
parents:
diff changeset
307 Lst => Index_Type'Pred (Position))
kono
parents:
diff changeset
308 and then Range_Shifted
kono
parents:
diff changeset
309 (Left => Container,
kono
parents:
diff changeset
310 Right => Add'Result,
kono
parents:
diff changeset
311 Fst => Position,
kono
parents:
diff changeset
312 Lst => Last (Container),
kono
parents:
diff changeset
313 Offset => 1);
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 function Remove
kono
parents:
diff changeset
316 (Container : Sequence;
kono
parents:
diff changeset
317 Position : Index_Type) return Sequence
kono
parents:
diff changeset
318 -- Returns a new sequence which contains the same elements as Container
kono
parents:
diff changeset
319 -- except that the element at position Position has been removed.
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 with
kono
parents:
diff changeset
322 Global => null,
kono
parents:
diff changeset
323 Pre => Position in Index_Type'First .. Last (Container),
kono
parents:
diff changeset
324 Post =>
kono
parents:
diff changeset
325 Length (Remove'Result) = Length (Container) - 1
kono
parents:
diff changeset
326 and then Range_Equal
kono
parents:
diff changeset
327 (Left => Container,
kono
parents:
diff changeset
328 Right => Remove'Result,
kono
parents:
diff changeset
329 Fst => Index_Type'First,
kono
parents:
diff changeset
330 Lst => Index_Type'Pred (Position))
kono
parents:
diff changeset
331 and then Range_Shifted
kono
parents:
diff changeset
332 (Left => Remove'Result,
kono
parents:
diff changeset
333 Right => Container,
kono
parents:
diff changeset
334 Fst => Position,
kono
parents:
diff changeset
335 Lst => Last (Remove'Result),
kono
parents:
diff changeset
336 Offset => 1);
kono
parents:
diff changeset
337
kono
parents:
diff changeset
338 ---------------------------
kono
parents:
diff changeset
339 -- Iteration Primitives --
kono
parents:
diff changeset
340 ---------------------------
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 function Iter_First (Container : Sequence) return Extended_Index with
kono
parents:
diff changeset
343 Global => null;
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 function Iter_Has_Element
kono
parents:
diff changeset
346 (Container : Sequence;
kono
parents:
diff changeset
347 Position : Extended_Index) return Boolean
kono
parents:
diff changeset
348 with
kono
parents:
diff changeset
349 Global => null,
kono
parents:
diff changeset
350 Post =>
kono
parents:
diff changeset
351 Iter_Has_Element'Result =
kono
parents:
diff changeset
352 (Position in Index_Type'First .. Last (Container));
kono
parents:
diff changeset
353 pragma Annotate (GNATprove, Inline_For_Proof, Iter_Has_Element);
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 function Iter_Next
kono
parents:
diff changeset
356 (Container : Sequence;
kono
parents:
diff changeset
357 Position : Extended_Index) return Extended_Index
kono
parents:
diff changeset
358 with
kono
parents:
diff changeset
359 Global => null,
kono
parents:
diff changeset
360 Pre => Iter_Has_Element (Container, Position);
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 private
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 pragma SPARK_Mode (Off);
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 package Containers is new Ada.Containers.Functional_Base
kono
parents:
diff changeset
367 (Index_Type => Index_Type,
kono
parents:
diff changeset
368 Element_Type => Element_Type);
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 type Sequence is record
kono
parents:
diff changeset
371 Content : Containers.Container;
kono
parents:
diff changeset
372 end record;
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 function Iter_First (Container : Sequence) return Extended_Index is
kono
parents:
diff changeset
375 (Index_Type'First);
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 function Iter_Next
kono
parents:
diff changeset
378 (Container : Sequence;
kono
parents:
diff changeset
379 Position : Extended_Index) return Extended_Index
kono
parents:
diff changeset
380 is
kono
parents:
diff changeset
381 (if Position = Extended_Index'Last then
kono
parents:
diff changeset
382 Extended_Index'First
kono
parents:
diff changeset
383 else
kono
parents:
diff changeset
384 Extended_Index'Succ (Position));
kono
parents:
diff changeset
385
kono
parents:
diff changeset
386 function Iter_Has_Element
kono
parents:
diff changeset
387 (Container : Sequence;
kono
parents:
diff changeset
388 Position : Extended_Index) return Boolean
kono
parents:
diff changeset
389 is
kono
parents:
diff changeset
390 (Position in Index_Type'First ..
kono
parents:
diff changeset
391 (Index_Type'Val
kono
parents:
diff changeset
392 ((Index_Type'Pos (Index_Type'First) - 1) + Length (Container))));
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 end Ada.Containers.Functional_Vectors;