!standard A.18.3(90/2) 10-10-22 AC95-00206/01 !class confirmation 10-10-22 !status received no action 10-10-22 !status received 10-07-19 !subject Containers and type Cursor !summary Subject : The Package Containers.Doubly Linked Lists and the type Cursor Reference : Ada 2005 (and project for 2012) Author : J. C. Fournier, Equipe Combinatoire & Optimization, University Pierre et Marie Curie (Paris 6, France) Keywords : Ada, Containers, Doubly Linked Lists, Cursor Discussion : A reference to the container is included in the cursor value (cf. Annoted Ada Reference Manual, 90.a/2). But, it doesnt seem possible to have access to this information. However, such an access to the container would be very useful when several lists are managed in a program, and a function such as Contains is used, in an efficient way when, for instance, the type Element_Type is discrete. Suggestion : Why not give this possibility (in Ada 2012) ? *************************************************************** From: Randy Brukardt Sent: Monday, July 19, 2010 2:59 PM > A reference to the container is included in the cursor value (cf. > Annoted Ada Reference Manual, 90.a/2). But, it doesnt seem possible to > have access to this information. However, such an access to the > container would be very useful when several lists are managed in a > program, and a function such as Contains is used, in an efficient way > when, for instance, the type Element_Type is discrete. > Suggestion : Why not give this possibility (in Ada 2012) ? This capability was not provided in Ada 2005 because it was not safe: if the container is destroyed after an access value is created, a dangling reference is created. While cursors themselves have a similar problem, there are a number of techniques to minimize the problem (for instance, using matching serial numbers which are changed when the container is destroyed). Those techniques can't be used with a bare access value. Ada 2012 will have "syntax sugar" which will make such accesses safer (mainly by preventing them from being copied). So it probably would be possible to provide such access (while expensive). But there are still issues to consider. For instance, is the access provided a constant access (only allowing reading) or a variable access? The current use of cursors only allow reading of the implicit container access; if we retained that, the possible uses of the container from a cursor would be rather limited. I also have to wonder whether the other new features planned for Ada 2012 would reduce or eliminate the need for such access anyway. Since the new accessor functions will allow direct access to the elements of a container, there shouldn't be any need to get the container for those purposes. Presuming that we are also sticking with read-only access, what is left? The only useful thing I can think of is Find; it would seem like a lot of overhead to add container accessors for the only purpose of calling Find. If Find is a real concern, (and the only concern), perhaps it would be better to add new versions of Find that don't need a container (using a cursor instead). Much less complication and probably safer as well. *************************************************************** From: Bob Duff Sent: Monday, July 19, 2010 3:40 PM > Discussion : A reference to the container is included in the cursor = > value (cf. Annoted Ada Reference Manual, 90.a/2). But, it doesnt seem > = possible to have access to this information. However, such an access > to = the container would be very useful when several lists are managed > in a = program, and a function such as Contains is used, in an > efficient way = when, for instance, the type Element_Type is discrete. True. On the downside, it would make it impossible to create an unchecked/unsafe version of the package that eliminates the checks. *************************************************************** From: Randy Brukardt Sent: Monday, July 19, 2010 6:29 PM I don't follow. The pointer internal to a Cursor is used for more than just checking; it's necessary to access the elements for a Vector (since the cursor is just an index) and I believe there are other operations with similar requirements. I wouldn't expect the existence of the container access to change between a checked and unchecked container version. ***************************************************************