From: Adam Beneschan <adam@irvine.com>
Subject: Re: Generics with concrete and class-wide types
Date: Tue, 1 Apr 2008 14:17:56 -0700 (PDT)
Date: 2008-04-01T14:17:56-07:00 [thread overview]
Message-ID: <4d05402e-f953-4a75-91c1-8fccbcc2cd3e@s37g2000prg.googlegroups.com> (raw)
In-Reply-To: fsu4r8$b53$1@jacob-sparre.dk
On Apr 1, 1:10 pm, "Randy Brukardt" <ra...@rrsoftware.com> wrote:
> "Adam Beneschan" <a...@irvine.com> wrote in message
>
> news:f0879dc0-7498-48f7-8d44-9856316d35ce@s19g2000prg.googlegroups.com...
> ...
>
> > What's missing here is a way to specify a generic formal subprogram
> > that must be a primitive operation of some tagged type (possibly a
> > generic formal tagged type),
>
> No, it's not missing. That's what abstract formal subprograms are for. See
> specifically 12.6(8.4-8.5/2).
Ah ha, thank you! No, I didn't realize that's what they were for,
perhaps because "abstract" isn't a synonym for "dispatching", but it
makes sense now that you pointed me in the right direction.
> I'm not sure that helps in this case, but feel free to try. ;-).
I think it does help. If my previous example were changed to this:
generic
type Element is private;
type Iterator_Root is tagged private;
with function Get (I : in Iterator_Root) return Element
is abstract <>; -- unspeakable syntax??
... other operations
package SP_For_Class is
procedure Some_Procedure_Class (I : in Iterator_Root'Class);
end SP_For_Class;
with Some_Procedure;
package body SP_For_Class is
function Dispatching_Get (I : in Iterator_Root'Class)
return Element is
begin
return Get (I);
end Dispatching_Get;
... similarly for other operations
procedure SP_Inst is new Some_Procedure
(Element, Iterator_Root'Class,
Dispatching_Get, ...other operations);
procedure Some_Procedure_Class (I : in Iterator_Root'Class)
renames SP_Inst;
end SP_For_Class;
then the call to Get inside Dispatching_Get would be legal. Then, in
Maciej's case, if he wants a Some_Procedure instance that would work
on a class-wide type and dispatch, he could instantiate SP_For_Class
with the specific type, and then Some_Procedure_Class declared in the
instance would be the procedure he's looking for. At least I think
this would work---I haven't tried it. It's a little klunky to declare
the SP_For_Class generic, but at least it wouldn't involve any
duplicated code. And if it works, it will work without waiting for a
solution to AI05-71.
-- Adam
next prev parent reply other threads:[~2008-04-01 21:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-31 20:22 Generics with concrete and class-wide types Maciej Sobczak
2008-03-31 23:38 ` Adam Beneschan
2008-04-01 20:10 ` Randy Brukardt
2008-04-01 21:17 ` Adam Beneschan [this message]
2008-04-01 0:23 ` Randy Brukardt
2008-04-01 3:57 ` Eric Hughes
2008-04-01 6:58 ` christoph.grein
2008-04-01 7:22 ` Georg Bauhaus
2008-04-01 9:42 ` Dmitry A. Kazakov
2008-04-01 9:51 ` Maciej Sobczak
2008-04-01 10:53 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox