From: BBardin@ADA20.ISI.EDU
Subject: Avoiding Recursion with Overloaded Operators
Date: Wed, 24-Sep-86 12:49:28 EDT [thread overview]
Date: Wed Sep 24 12:49:28 1986
Message-ID: <8609252230.AA03642@ucbvax.Berkeley.EDU> (raw)
In response to the question (from Pat Rogers at High Tech Lab) seeking a way
to avoid a recursive call to an overloaded operator, consider:
package P is
type LP is limited private;
function "=" (Left, Right : LP) return Boolean;
private
type T is access Integer;
type LP is new T;
end P;
package body P is
function "=" (Left, Right : LP) return Boolean is
begin
if T (Left) = T (Right) or else
Left.all = Right.all then
return True;
else
return False;
end if;
exception
when Constraint_Error =>
return False;
end "=";
end P;
--------
Other (less desirable) solutions include testing 'Left.all' and
'Right.all' individually to see if the both generate constraint
errors, or (a little better) renaming the predefined operator before
overloading it.
The recommended solution was provided by Bryce Bardin, and has been
tested on a validated compiler.
Sincerely,
John Prentice
-------
reply other threads:[~1986-09-24 16:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox