Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: Generics wi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 11 Topic 5629 of 5830
Post > Topic >>

Re: Generics with concrete and class-wide types

by Adam Beneschan <adam@[EMAIL PROTECTED] > Apr 1, 2008 at 02:17 PM

On Apr 1, 1:10 pm, "Randy Brukardt" <ra...@[EMAIL PROTECTED]
> wrote:
> "Adam Beneschan" <a...@[EMAIL PROTECTED]
> wrote in message
>
>
news:f0879dc0-7498-48f7-8d44-9856316d35ce@[EMAIL PROTECTED]
> ...
>
> > 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
 




 11 Posts in Topic:
Generics with concrete and class-wide types
Maciej Sobczak <see.my  2008-03-31 13:22:10 
Re: Generics with concrete and class-wide types
Adam Beneschan <adam@[  2008-03-31 16:38:41 
Re: Generics with concrete and class-wide types
"Randy Brukardt"  2008-04-01 15:10:13 
Re: Generics with concrete and class-wide types
"Randy Brukardt"  2008-03-31 19:23:03 
Re: Generics with concrete and class-wide types
Eric Hughes <eric.eh9@  2008-03-31 20:57:57 
Re: Generics with concrete and class-wide types
christoph.grein@[EMAIL PR  2008-03-31 23:58:59 
Re: Generics with concrete and class-wide types
Georg Bauhaus <rm.tsoh  2008-04-01 09:22:56 
Re: Generics with concrete and class-wide types
"Dmitry A. Kazakov&q  2008-04-01 11:42:18 
Re: Generics with concrete and class-wide types
Maciej Sobczak <see.my  2008-04-01 02:51:19 
Re: Generics with concrete and class-wide types
"Dmitry A. Kazakov&q  2008-04-01 12:53:04 
Re: Generics with concrete and class-wide types
Adam Beneschan <adam@[  2008-04-01 14:17:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 14:55:27 CDT 2008.