Is this a bug?
Lars T. Kyllingstad
public at kyllingen.NOSPAMnet
Sun Jan 9 23:19:33 PST 2011
On Sun, 09 Jan 2011 23:09:26 -0600, Christopher Nicholson-Sauls wrote:
> On 01/09/11 16:28, Sean Eskapp wrote:
>> This code works fine:
>>
>> int[] arr = [ 1, 2, 3, 4, 5 ];
>> auto myMax = function int(int a, int b) { return (a > b) ? a :
b; };
>> auto biggest = reduce!(myMax)(arr);
>>
>> But passing the function literal directly to reduce causes an error. Is
>> this intentional?
>
> I believe this is because binaryFun (which reduce uses) takes a template
> alias parameter, which must refer to something bound -- aka, having a
> name.
Template alias parameters do accept anonymous functions now (but I don't
think it's that long ago that they didn't). This works in DMD 2.051, at
least:
auto biggest = reduce!((a, b) { return a > b ? a : b; })(arr);
-Lars
More information about the Digitalmars-d
mailing list