comp.lang.ada
 help / color / mirror / Atom feed
* Avoiding Recursion with Overloaded Operators
@ 1986-09-24 16:49 BBardin
  0 siblings, 0 replies; only message in thread
From: BBardin @ 1986-09-24 16:49 UTC (permalink / 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
-------

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1986-09-24 16:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1986-09-24 16:49 Avoiding Recursion with Overloaded Operators BBardin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox