Partially instantiating templates?

Simen kjaeraas simen.kjaras at gmail.com
Tue Feb 1 07:41:33 PST 2011


Magnus Lie Hetland <magnus at hetland.org> wrote:

> On 2011-02-01 16:09:22 +0100, Simen kjaeraas said:
>
>> Magnus Lie Hetland <magnus at 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...?

Nope, still std.functional. That's where the string is mixin'ed.

But thanks for noting that, I've filed it as issue #5513.


-- 
Simen


More information about the Digitalmars-d-learn mailing list