www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - UFCS in template function

reply "ixid" <nuaccount gmail.com> writes:
UFCS does not work in this template where the normal function 
call syntax will work:

template test(alias fun) {
	auto test(T)(T n) {
		return n.fun;
	}
}

Is this the same as the inability to use UFCS with functions 
declared in the same scope as the call? Is there no way to 
address this issue without messing with calling class members 
(that is what I understand to be the reason for the limitation on 
UFCS, I may have misunderstood). It also prevents the use of 
function literals in UFCS chains which seems like a great pity 
and the loss of what should be a very natural part of the 
language.
Aug 28 2013
parent reply Jacob Carlborg <doob me.com> writes:
On 2013-08-28 23:28, ixid wrote:
 UFCS does not work in this template where the normal function call
 syntax will work:

 template test(alias fun) {
      auto test(T)(T n) {
          return n.fun;
      }
 }

 Is this the same as the inability to use UFCS with functions declared in
 the same scope as the call? Is there no way to address this issue
 without messing with calling class members (that is what I understand to
 be the reason for the limitation on UFCS, I may have misunderstood). It
 also prevents the use of function literals in UFCS chains which seems
 like a great pity and the loss of what should be a very natural part of
 the language.
UFCS only works for module level functions. -- /Jacob Carlborg
Aug 28 2013
next sibling parent "ixid" <nuaccount gmail.com> writes:
On Thursday, 29 August 2013 at 06:23:32 UTC, Jacob Carlborg wrote:
 UFCS only works for module level functions.
What is the reason for this limitation?
Aug 29 2013
prev sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 8/29/13, Jacob Carlborg <doob me.com> wrote:
 UFCS only works for module level functions.
However it does work for local imports (I think this was new in 2.063): void main() { import std.range; assert([].empty); // ok }
Aug 29 2013
parent Jacob Carlborg <doob me.com> writes:
On 2013-08-29 22:02, Andrej Mitrovic wrote:

 However it does work for local imports (I think this was new in 2.063):

 void main()
 {
      import std.range;
      assert([].empty);  // ok
 }
"empty" is declared at module scope. -- /Jacob Carlborg
Aug 29 2013