4.1.5 User-Defined References
Given a discriminated type T, the following
type-related operational aspect may be specified:
This aspect is specified by a name that denotes
an access discriminant declared for the type T.
for Implicit_Dereference: Mechanism
for user-defined implicit .all.
A (view of a) type with a specified Implicit_Dereference
aspect is a reference type. A reference
object is an object of a reference type. The
discriminant named by the Implicit_Dereference aspect is the reference
discriminant of the reference type or reference object.
is a name
that identifies a reference object, and denotes the object or subprogram
designated by the reference discriminant of the reference object.]
Name Resolution Rules
Given a reference type T, the Implicit_Dereference
aspect is inherited by descendants of type T if not overridden.
If a descendant type constrains the value of the reference discriminant
of T by a new discriminant, that new discriminant is the reference
discriminant of the descendant. [If the descendant type constrains the
value of the reference discriminant of T by an expression
other than the name
of a new discriminant, a generalized_reference
that identifies an object of the descendant type denotes the object or
subprogram designated by the value of this constraining expression.]
The evaluation of a generalized_reference
consists of the evaluation of the reference_object_name
and a determination of the object or subprogram designated by the reference
discriminant of the named reference object. A
check is made that the value of the reference discriminant is not the
null access value. Constraint_Error is raised if
this check fails. The generalized_reference
denotes the object or subprogram designated by the value of the reference
discriminant of the named reference object.
type Ref_Element(Data : access Element) is
new Ada.Finalization.Limited_Controlled with private
with Implicit_Dereference => Data;
-- This Ref_Element type is a "reference" type.
-- "Data" is its reference discriminant.
function Find(C : access Container; Key : String) return Ref_Element;
-- Return a reference to an element of a container
Find(C, "abc") := Element'(...); -- Assign through a reference
-- This is equivalent to:
-- Find(C, "abc").Data.all := Element'(...);
Extensions to Ada 2005
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe