Cannot use the same template arguments on function as the ones on struct

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Feb 11 23:34:52 PST 2015


On Thursday, February 12, 2015 07:11:12 Stefan Koch via Digitalmars-d-learn wrote:
> DMD cannot overload templated and non-templated functions
> an empty template argument is needed

That's not actually true anymore. However, you have to be really careful
when you do it, because it pretty much always favors calling the
non-templated overload when it can, so you need to be very sure that the
right overloads are getting called with the various types. Ultimately, I
think that it's just better to templatize all of the functions and then get
the constraints right, but if the set of types that are supposed to use the
templated overload aren't even vaguely related to the non-templated
overload, then you're probably okay. However, I've found that stuff like
constness and inheritance tends to make it so that the non-templated
overload ends up being called when I want the templated one to be called.
So, in the end, it just pays to test and make sure that the right overload
gets called for the various types that are supposed to be used with them.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list