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: User-define...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 22 of 23 Topic 5595 of 5930
Post > Topic >>

Re: User-defined type attributes

by "Randy Brukardt" <randy@[EMAIL PROTECTED] > Mar 17, 2008 at 04:03 PM

"Eric Hughes" <eric.eh9@[EMAIL PROTECTED]
> wrote in message
news:c6b7e0b5-6b81-486a-8054-becd0df9842b@[EMAIL PROTECTED]
> Tagged types do work better, sure.  But they're not a panacea,
> either.  It would a mistake to address other difficulties with types
> by shoehorning "solutions" to them into tags.  And in the last couple
> of days I've realized the problems with untagged types as formal
> parameters is much greater than the absence of dot-notation.
>
> So here's a brief example.  I'm writing a smart accessor package set
> right now.  As something of an exercise, I'm doing this as generically
> as possible.  So I'm looking to write code that can use both intrusive
> (part of the managed object) and accretive (separate from the managed
> object) allocation strategies for reference counts.  And I want to do
> it without making the accessor types tagged.  Since an intrusive
> accessor is simple a wrapped-up access object, adding a tag would
> double the machine size of an object.  I consider this a poor result
> for a system-level library.
>
> My first foray at solving this was to use a formal type parameter for
> the implementation of the accessor.  The intrusive implementation
> would contain just an access object; the accretive one would have that
> plus an access to a reference count.  Pretty simple, so I thought.
> But without using a tagged type in the formal parameter definition,
> there's no visibility either for record components or for implicit
> visibility of operators on that type.  Thus I couldn't get at
> components either directly or indirectly.  I discarded that approach.
>
> It's a shame really, because it would otherwise be a natural
> representation of variety of in possible implementations.  I'm still
> looking at other ways of approaching the problem.  I'm beginning to
> suspect that doing this may be impossible, but I don't have an
> argument yet.

In cases like these, you have to pass accessor routines explicitly.
Something like:

generic
     type T is private;
     procedure Increment_Count (Obj : in out T) is <>;
     function Count (Obj : in T) is <>:
     ...
package Whatever is ...

Note the use of <> in these formal subprogram declarations. It gives a
default for the subprograms such that a routine with the right name and
profile automatically matches. (Why you can't have such defaults for types
is unknown by me...) This makes the instantiations less annoying (but you
do
need to declare the appropriate routines somewhere).

You can wrap these things up and use them as formal packages if they are
common, so you don't necessarily have to end up with lots of generics with
a
hundred parameters.

I would prefer to use an interface or tagged type here, but obviously you
can't do that. This is not a perfect solution, but it works and is
commonly
used.

                                  Randy.
 




 23 Posts in Topic:
User-defined type attributes
Eric Hughes <eric.eh9@  2008-03-12 11:58:29 
Re: User-defined type attributes
"Dmitry A. Kazakov&q  2008-03-12 22:23:43 
Re: User-defined type attributes
Eric Hughes <eric.eh9@  2008-03-13 11:32:23 
Re: User-defined type attributes
"Dmitry A. Kazakov&q  2008-03-13 20:58:15 
Re: User-defined type attributes
"Randy Brukardt"  2008-03-13 20:46:41 
Re: User-defined type attributes
"Randy Brukardt"  2008-03-13 20:46:41 
Re: User-defined type attributes
"Randy Brukardt"  2008-03-13 20:46:41 
Re: User-defined type attributes
"Dmitry A. Kazakov&q  2008-03-14 10:00:46 
Re: User-defined type attributes
"Randy Brukardt"  2008-03-14 22:04:53 
Re: User-defined type attributes
"Dmitry A. Kazakov&q  2008-03-15 10:33:38 
Re: User-defined type attributes
"Randy Brukardt"  2008-03-13 20:46:37 
Re: User-defined type attributes
Eric Hughes <eric.eh9@  2008-03-13 20:55:27 
Re: User-defined type attributes
"Dmitry A. Kazakov&q  2008-03-14 10:01:47 
Re: User-defined type attributes
Eric Hughes <eric.eh9@  2008-03-13 21:41:21 
Re: User-defined type attributes
"Randy Brukardt"  2008-03-14 22:20:19 
Re: User-defined type attributes (replacing genericity)
Eric Hughes <eric.eh9@  2008-03-14 10:51:25 
Re: User-defined type attributes (replacing genericity)
"Dmitry A. Kazakov&q  2008-03-14 19:58:18 
Re: User-defined type attributes (replacing genericity)
"Randy Brukardt"  2008-03-14 23:01:56 
Re: User-defined type attributes
Eric Hughes <eric.eh9@  2008-03-14 11:04:33 
Re: User-defined type attributes (replacing genericity)
Eric Hughes <eric.eh9@  2008-03-14 13:19:47 
Re: User-defined type attributes
Eric Hughes <eric.eh9@  2008-03-16 21:38:37 
Re: User-defined type attributes
"Randy Brukardt"  2008-03-17 16:03:10 
Re: User-defined type attributes
Eric Hughes <eric.eh9@  2008-03-17 14:58:54 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sun Oct 12 4:45:59 CDT 2008.