On 2011-02-01 16:09:22 +0100, Simen kjaeraas said:

Magnus Lie Hetland <mag...@hetland.org> wrote:

Sort of related (though perhaps only remotely) is the following, which won't compile (Error: static assert "Bad unary function: f(a) for type int"):

Not related. unaryFun and binaryFun are simply glorified string mixins,
and thus can only access functions that are available in the modules
where they are mixed in. That would be std.functional. Because of that,
local functions may not be used as string arguments for *naryFun.

That certainly makes sense. I just got thrown off by the example in std.algorithm:

 uint hashFun(string) { ... expensive computation ... }
 string[] array = ...;
 // Sort strings by hash, slow
 sort!("hashFun(a) < hashFun(b)")(array);

The only way this could work would be if hashFun was available to the sort template, I guess...?

--
Magnus Lie Hetland
http://hetland.org

Reply via email to