In the 'to_Stack' function, the Capacity is reserved correctly but in the
test program when the stack is created and assigned to a variable, the capacity
is 0.
On 2023-03-19 07:17, Rod Kay wrote:
In the 'to_Stack' function, the Capacity is reserved correctly but
in the test program when the stack is created and assigned to a
variable, the capacity is 0.
I think this is acceptable behavior. See ARM A.18.2 (147.19/3, 147.20/3,
& 147.b/3) (http://www.ada-auth.org/standards/aarm12_w_tc1/html/AA-A-18-2.html).
The first two sections define the behavior of procedure Assign, while
the last states "Assign(A, B) and A := B behave identically".
Assign (A, B) only changes the capacity of A if A.Capacity < B.Length.
So if the compiler does not use build-in-place for the initialization of
the variable, then the assignment of the function result should not
change the capacity of the variable from its (apparent) default of zero (there is, of course, no requirement for the capacity of a default-initialized vector).
The discussion of capacities for vectors is only meaningful for a subset
of possible implementations, so messing with capacities may have no meaningful effect at all.
For an unbounded stack based on a linked list (with no concept of
capacity) you could use
PragmARC.Data_Structures.Stacks.Unbounded.Unprotected (https://github.com/jrcarter/PragmARC/blob/Ada-12/pragmarc-data_structures-stacks-unbounded-unprotected.ads).
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 379 |
Nodes: | 16 (2 / 14) |
Uptime: | 44:46:23 |
Calls: | 8,141 |
Calls today: | 4 |
Files: | 13,085 |
Messages: | 5,858,055 |