Non-virtual private struct inheritance

monarch_dodra monarchdodra at gmail.com
Thu Aug 23 05:44:09 PDT 2012


In C++, it is a very common practice, when writing a struct 
template, to have said template derive from a base non-template 
struct. This makes sure there is no executable bloat, and, more 
often than not, the inheritance is private, so invisible to users 
(no "interface leak").

For instance, std::list is a classic example of this: First, you 
have the template create a node, and then you defer to the base 
class for all insertions/deletions, that don't really care about 
what a T is.

My first question is: Is such an approach even encouraged in D? 
Or is the module compilation system able to see through what 
does/doesn't depend on these parameters?

Can be swapping inheritance for member variables, or free 
standing external methods. Both works most of the time, but 
neither are quite as polyvalent.

...

D being a heavily templated system language, executable size is 
something that should be controlable, correct? Is there any 
chance we could see this kind of limited inheritance for structs? 
As in just basic non-polymorphous inheritance? I seem to remember 
a few threads about other users wishing for inheritance with 
structs...


More information about the Digitalmars-d mailing list