Smart pointers instead of GC?

Walter Bright newshound2 at digitalmars.com
Mon Feb 3 19:45:53 PST 2014


On 2/3/2014 7:24 PM, Michel Fortin wrote:
> But, you could implement this as a template function if you absolutely need to
> transfer nullability, and the template will actually make things more efficient
> because the template instantiated with a non-nullable function argument will
> optimize away the unnecessary branch.

Yes, you could use a template, but the idea was to avoid bloat in the executable 
by having multiple sets of functions that differ only by their mangled name. 
Furthermore, templates cannot be used to create virtual functions.


> And to get to the root of this, I think it'd be much more useful to have a "same
> type as input" stand-in, because notice how in the above function if you pass a
> DerivedObject, you'll get an Object returned, losing the derived part? Exact
> same problem, and we've been living with it for decades.

The const issue is a recurring theme in a lot of C++ code, the derived type one 
just doesn't seem to come up.

Also, what is being looked at to transfer is the qualifier, not the type, as the 
type may actually change (such as returning a pointer to a field of the argument).



More information about the Digitalmars-d mailing list