UFCS for templates

Jonathan M Davis jmdavisProg at gmx.com
Thu Aug 8 11:04:29 PDT 2013


On Thursday, August 08, 2013 19:35:01 JS wrote:
> Can we have UFCS for templates?
> 
> e.g.,
> 
> T New(T, A...)(A args) { }
> 
> 
> T t = T.New(args);
> 
> 
> Note, in this case, the type parameter is substituted.

And how is the compiler supposed to know whether T is being passed as a 
template argument or a function argument? In some cases, it'll be clear. In 
others (such as with alias parameters), the compiler will have no way of 
knowing.

Also, I think that allowing it would increase confusion for little benefit 
anyway. The primary benefit of UFCS is making it so that generic code can call 
functions without caring about whether they're member functions or free 
functions. There is no such benefit with template arguments.

- Jonathan M Davis


More information about the Digitalmars-d mailing list