auto ref and non-templated functions

Jonathan M Davis jmdavisProg at gmx.com
Tue Dec 25 03:09:33 PST 2012


On Tuesday, December 25, 2012 11:44:45 Jens Mueller wrote:
> And the solution needs to be non-template based because it needs to work
> with classes? Is that the only reason?

That and if it's not non-templated, it's impossible to have auto ref functions 
which hide their implementation for those who need to use .di files to hide the 
implementation. It also might also be necessary if you need to be able to 
guarantee that the function exists. Basically, any situation where you can't 
use a template or where it's undesirable to use a template, the current auto 
ref doesn't work. But the big one is classes, as templated functions can't be 
virtual. Without a non-templated solution, virtual functions will never be 
able to do the equivalent of C++'s const& or anything like it, meaning that 
they'll incur overhead due to unnecessary copies in many cases.

- Jonathan M Davis


More information about the Digitalmars-d mailing list