From: mheaney@ni.net (Matthew Heaney)
Subject: Implementation of "=" (Ada83)
Date: 1996/07/13
Date: 1996-07-13T00:00:00+00:00 [thread overview]
Message-ID: <mheaney-1307961304430001@news.ni.net> (raw)
I have a question about how to implement the "=" for limited private types
in Ada83.
Suppose we have
package T_Package is
type T is limited private;
function "=" (L, R : T) return Boolean;
private
type T is
record
A, B : Integer;
end record;
end;
package body T_Package is
function "=" (L, R : T) return Boolean is
begin
return ?; -- What goes here?
end;
end;
I think the LRM says that an equality operator is "implicitly declared" at
the point of declaration of the full view of the private type. Is this
correct? If so, how do I refer to it?
If I did this
function "=" (L, R : T) return Boolean is
begin
return L = R;
end;
isn't this just recursive?
Or do I just have to bite the bullet and do this
function "=" (L, R : T) return Boolean is
begin
return L.A = R.A and L.B = R.B;
end;
Is this the expected implementation?
There's one other implementation technique I thought of, that I don't
really like, but here it is:
package T_Package is
...
private
type T_Representation is
record
A, B : Integer;
end record;
type T is new T_Representation;
end;
package body T_Package is
function "=" (L, R : T) return Boolean is
begin
return T_Representation (L) = T_Representation (R);
end;
end;
At least here, I can directly refer to the "=" for the record itself, and
not to T's "=".
Maybe this is what the Ada language designers intended in this case?
Can anyone out there explain how they would implement the "=" for T?
Thanks a bunch!
matt
--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
mheaney@ni.net
(818) 985-1271
next reply other threads:[~1996-07-13 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-07-13 0:00 Matthew Heaney [this message]
1996-07-15 0:00 ` Implementation of "=" (Ada83) Jon S Anthony
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox