comp.lang.ada
 help / color / mirror / Atom feed
From: adam@irvine.com (Adam Beneschan)
Subject: Dispatching and generics - language lawyer question
Date: 22 Jul 2002 16:13:43 -0700
Date: 2002-07-22T23:13:43+00:00	[thread overview]
Message-ID: <b4682ab7.0207221513.4eb610de@posting.google.com> (raw)

I have a couple questions about what's supposed to happen when a
generic is instantiated with a class-wide type as an actual type.  I'm
hoping that someone who really understands the intricacies of the
language will be kind enough to answer, and provide chapter and verse
from the RM to explain the correct answer.

(1) What is the correct output of the program below?

(2) What would be the correct output if "private" in line [A] is
changed to
    "tagged private"?

I'm pretty sure the answer to (1) is FALSE, since the "=" on line [B]
in the instance denotes the predefined "=" declared for T1 in the
generic, and not the "=" "defined" for the class-wide type, by
8.3(13).  I'm less clear about the answer to (2).  Here, the "="
implicitly declared for T1 is a dispatching operation, and thus should
dispatch if a controlling operand is of a class-wide type (3.9.2(5)),
but it's not clear to me whether the operands in this case are treated
as if they were of the formal type (which is not class-wide) or of the
actual type (which is class-wide).

Thanks in advance for your help.

				-- Adam




generic
    type T1(<>) is private;            -- [A]
package Pak1 is
    type T1_Access is access T1;
    function Check_Equal (X, Y : T1_Access) return boolean;
end Pak1;    

package body Pak1 is
    function Check_Equal (X, Y : T1_Access) return boolean is
    begin
        return X.all = Y.all;          -- [B]
    end Check_Equal;
end Pak1;    

package Pak2 is
    type Root_Type is tagged record
        F1 : Integer;
    end record;
end Pak2;

with Pak2;
package Pak3 is
    type Child is new Pak2.Root_Type with record
        F2 : Integer;
    end record;
    function "=" (Left, Right : Child) return boolean;
end Pak3;    
        
package body Pak3 is
    function "=" (Left, Right : Child) return boolean is
    begin
        return Left.F1 = Right.F1 and then 
               abs Left.F2 = abs Right.F2;
    end "=";
end Pak3;    
        

with Pak1;
with Pak2;
with Pak3;
with Text_IO;
procedure Test62 is
    package Pak1_Inst is new Pak1 (Pak2.Root_Type'Class);
    A1 : Pak1_Inst.T1_Access;
    A2 : Pak1_Inst.T1_Access;
    B  : Boolean;
begin
    A1 := new Pak3.Child' (F1 => 4, F2 => 6);
    A2 := new Pak3.Child' (F1 => 4, F2 => -6);
    B := Pak1_Inst.Check_Equal (A1, A2);
    Text_IO.Put_Line (Boolean'Image (B));
end Test62;



             reply	other threads:[~2002-07-22 23:13 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-22 23:13 Adam Beneschan [this message]
2002-07-23 15:42 ` Dispatching and generics - language lawyer question Stephen Leake
2002-07-24 15:37   ` Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
2002-07-24  5:33 Grein, Christoph
2002-07-24 22:55 ` Robert A Duff
2002-07-25 15:46   ` Ben Brosgol
2002-07-29 20:38     ` Robert A Duff
2002-07-31 22:52       ` Dmitry A.Kazakov
2002-07-31 20:18         ` Robert A Duff
2002-08-02  1:15           ` Dmitry A.Kazakov
2002-08-01 16:30             ` Hyman Rosen
2002-08-02 23:42               ` Dmitry A.Kazakov
2002-08-02 15:49                 ` Hyman Rosen
2002-08-02 17:48                   ` Stephen Leake
2002-08-10  3:03                     ` Warren W. Gay VE3WWG
2002-08-05 11:15                   ` Dmitry A. Kazakov
2002-08-12 12:44                   ` Robert Dewar
2002-08-13 22:50           ` Randy Brukardt
2002-08-14  0:02             ` Robert A Duff
2002-07-25  0:40 ` Robert Dewar
replies disabled

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