New set class

Michiel nomail at please.com
Mon Feb 26 05:34:15 PST 2007


Frits van Bommel wrote:

>> Interesting trick. I missed the extra (). One problem, though. If I use
>> it like this:
>>
>> foreach_reverse(e ; x) { }
>>
>> Not specifying the element type (int). I get the "cannot infer type"
>> error, instead of our custom error message. Why can't the compiler infer
>> the type? Isn't it right in its face?
> 
> The code you <SNIP>ped didn't have that problem, so I presume you used
> the declaration Bill Baxter posted. Guess why I changed it for my
> example ;).
> The compiler can't infer the type in Bill's code because his
> opApplyReverse has the wrong signature. In order to get type deduction
> (as well as instantiation) opApplyReverse needs to have as parameter a
> delegate with the correct number of (inout) arguments that returns int.
> In my code I had
> ---
> void opApplyReverse()(int delegate(inout T)) { static assert(0,"don't be
> silly");}
> ---
> and it worked.

No, I used your code. I just tested again to be sure. It doesn't work.
If you leave out the 'int' in the foreach_reverse statement, the silly
error message doesn't get displayed.

-- 
Michiel



More information about the Digitalmars-d mailing list