comp.lang.ada
 help / color / mirror / Atom feed
* Generic abstracts
@ 1999-11-25  0:00 Lutz Donnerhacke
  1999-11-25  0:00 ` Lutz Donnerhacke
  1999-11-29  0:00 ` Tucker Taft
  0 siblings, 2 replies; 8+ messages in thread
From: Lutz Donnerhacke @ 1999-11-25  0:00 UTC (permalink / raw)


Somebody might remember a unspecific quotation from the reference manual
about prohibiting abstract declarations in generic packages.

In my current developemnt I came across this problem again.

generic
   type S (<>) is abstract tagged limited private;
package X is
   type T        is abstract new S with private;
   type T_Class  is access all T'Class;
   type Bla      is limited private;
   type Position is private;

   procedure Set (B : in out Bla;
                  E : in     T_Class);
		  
   function  Get (B : in     Bla) return T_Class;

   generic
      with procedure On_Item (E : in out S);
   procedure         Iterate (B : in     Bla);

   generic
      with function Is_Match (E : in S)   return Boolean;
   function         Find     (B : in Bla) return Position;
end X;

I will guarantee this interface (Set/Get) over several implementations.
The na�ve approach fails:

generic
   type S (<>) is abstract tagged limited private;
package X is
   type T       is abstract new S null record;
   type T_Class is access all T'Class;
   type Bla     is abstract tagged limited null record;

   procedure Set (B : in out Bla;
                  E : in     T_Class)            is abstract;
		  
   function  Get (B : in     Bla) return T_Class is abstract;
   
   generic
      with procedure On_Item (E : in out S);
   procedure         Iterate (B : in     Bla)    is abstract;
--                                               ^ missing ';'.
-- Providing a sensless dummy function works.

   generic
      with function Is_Match (E : in S)   return Boolean;
   function         Find     (B : in Bla) return Position is abstract;
--                                                        ^ missing ';'.
-- Providing a dummy function is not possible, because no return value exists.
end X;

The abstract definition should be used to ensure a consistent
inteface. I have two problems:
  - A generic procedure which can be missed on implementation.
    Raising an exception might be acceptable.
  - It is not possible to predefine a body for a generic function.
    No return value is available.
    Raising an exception does not stop the compiler from requiring
    a return value.    

Any hints?    




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1999-11-30  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-25  0:00 Generic abstracts Lutz Donnerhacke
1999-11-25  0:00 ` Lutz Donnerhacke
1999-11-29  0:00 ` Tucker Taft
1999-11-29  0:00   ` Lutz Donnerhacke
1999-11-29  0:00     ` Tucker Taft
1999-11-30  0:00       ` Robert A Duff
1999-11-30  0:00         ` Tucker Taft
1999-11-30  0:00       ` Lutz Donnerhacke

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