* Re: Default equality for generic formal types
2000-02-22 0:00 Default equality for generic formal types Matthew Heaney
@ 2000-02-21 0:00 ` R. Tim Coslet
2000-02-22 0:00 ` Andy
0 siblings, 1 reply; 3+ messages in thread
From: R. Tim Coslet @ 2000-02-21 0:00 UTC (permalink / raw)
See AARM 12.3(29.b)
For upward compatibility with Ada83 (which had this bug/feature) for
untagged types the the default function reverts to the predefined one. I
can't seem to locate the reference right now, but I believe that even if you
explicitly passed the instantion the "=" function, it still reverts to the
predefined one. However if your "=" function had a different name (like
"equal" you could pass that explicitly (a rename might work to accomplish
this workaround, but if not a wrapper function will).
This is not a problem with tagged types.
Matthew Heaney wrote:
> Suppose I have a generic subprogram like this:
>
> generic
> type Item_Type is private;
> with function Item_Eq (L, R : Item_Type)
> return Boolean is "=";
> procedure Generic_Op (O : T);
>
> Suppose further that the generic actual type is nontagged, and has
> overridden its predefined equality.
>
> To which equality does Item_Eq refer? The overridden version, or the
> predefined version? What does that default value for Item_Eq, "=", mean
> at the time of compilation of the generic?
>
> If the client does not explicitly pass in an item equality op during the
> instantiation (likely, because the type is nonlimited), then inside
> Generic_Op, what does Item_Eq refer to? Predefined equality, or the
> overridding version?
>
> Thanks in advance,
> Matt
^ permalink raw reply [flat|nested] 3+ messages in thread
* Default equality for generic formal types
@ 2000-02-22 0:00 Matthew Heaney
2000-02-21 0:00 ` R. Tim Coslet
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Heaney @ 2000-02-22 0:00 UTC (permalink / raw)
Suppose I have a generic subprogram like this:
generic
type Item_Type is private;
with function Item_Eq (L, R : Item_Type)
return Boolean is "=";
procedure Generic_Op (O : T);
Suppose further that the generic actual type is nontagged, and has
overridden its predefined equality.
To which equality does Item_Eq refer? The overridden version, or the
predefined version? What does that default value for Item_Eq, "=", mean
at the time of compilation of the generic?
If the client does not explicitly pass in an item equality op during the
instantiation (likely, because the type is nonlimited), then inside
Generic_Op, what does Item_Eq refer to? Predefined equality, or the
overridding version?
Thanks in advance,
Matt
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Default equality for generic formal types
2000-02-21 0:00 ` R. Tim Coslet
@ 2000-02-22 0:00 ` Andy
0 siblings, 0 replies; 3+ messages in thread
From: Andy @ 2000-02-22 0:00 UTC (permalink / raw)
This conflicts with my experience with both Apex and Gnat. If the "="
function is overridden, then this is the function used.
As usual with these sorts of question, I like to write a micro test
program
to see what really happens. It kind of helps me remember for next time.
Andy
PS Here my test program.
with Ada.Text_Io;
procedure Gen is
generic
type A is private;
with function "=" (L, R : in A) return Boolean is <>;
with function Eq (L, R : in A) return Boolean is "=";
procedure Check_Generic;
procedure Check_Generic is
L, R : A;
B : Boolean;
begin
L := R;
Ada.Text_Io.Put_Line ("-----");
B := L = R;
Ada.Text_Io.Put_Line ("-----");
B := Eq (L,R);
Ada.Text_Io.Put_Line ("-----");
end Check_Generic;
type Object is null record;
function "=" (L, R : in Object) return Boolean is
begin
Ada.Text_Io.Put_Line ("override invoked");
return True;
end;
procedure Check1 is
new Check_Generic (Object);
function "=" (L, R : in Integer) return Boolean is
begin
Ada.Text_Io.Put_Line ("int override invoked");
return True;
end;
procedure Check2 is
new Check_Generic (Integer);
begin
Check1;
Check2;
end Gen;
R. Tim Coslet wrote:
>
> See AARM 12.3(29.b)
>
> For upward compatibility with Ada83 (which had this bug/feature) for
> untagged types the the default function reverts to the predefined one. I
> can't seem to locate the reference right now, but I believe that even if you
> explicitly passed the instantion the "=" function, it still reverts to the
> predefined one. However if your "=" function had a different name (like
> "equal" you could pass that explicitly (a rename might work to accomplish
> this workaround, but if not a wrapper function will).
>
> This is not a problem with tagged types.
>
> Matthew Heaney wrote:
>
> > Suppose I have a generic subprogram like this:
> >
> > generic
> > type Item_Type is private;
> > with function Item_Eq (L, R : Item_Type)
> > return Boolean is "=";
> > procedure Generic_Op (O : T);
> >
> > Suppose further that the generic actual type is nontagged, and has
> > overridden its predefined equality.
> >
> > To which equality does Item_Eq refer? The overridden version, or the
> > predefined version? What does that default value for Item_Eq, "=", mean
> > at the time of compilation of the generic?
> >
> > If the client does not explicitly pass in an item equality op during the
> > instantiation (likely, because the type is nonlimited), then inside
> > Generic_Op, what does Item_Eq refer to? Predefined equality, or the
> > overridding version?
> >
> > Thanks in advance,
> > Matt
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2000-02-22 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-22 0:00 Default equality for generic formal types Matthew Heaney
2000-02-21 0:00 ` R. Tim Coslet
2000-02-22 0:00 ` Andy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox