UFCS for D
Walter Bright
newshound2 at digitalmars.com
Fri Mar 30 11:27:43 PDT 2012
On 3/29/2012 4:34 PM, Steven Schveighoffer wrote:
> But I realized after typing about 2 messages in response to this (and deleting
> them), you are right, there is a fundamental problem here. Because the template
> instantiation is based solely on the type. It does *not* include the type and
> whatever other modules you may have included that could define extension
> methods. I don't think it's an implementation issue, I think it's a design issue
> -- there simply is no way to do this.
Yes, you're right. The template is instantiated in the context of the template
definition, not the template instantiation. Hence, unless the extension methods
are in scope of the template definition, they will not be found.
I hadn't thought of this issue.
> So two possible sane rules:
> 1. A template instantiation can *only* use UFCS from functions defined in or
> imported from the module in which the template is defined. (i.e. the way it
> works now I think)
Yes, that is the way it works now.
> or
> 2. A template instantiation can *only* use UFCS from functions defined in or
> imported from the module in which the template is defined, *and* from functions
> as defined or imported by the module that defines the type on which UFCS is
> being used.
I would argue that:
3. An extension method for an argument of type template parameter T will be
looked up only in the instantiation scope.
More information about the Digitalmars-d-announce
mailing list