each & opApply

Alex sascha.orlov at gmail.com
Wed May 23 14:24:18 UTC 2018

On Wednesday, 23 May 2018 at 14:19:31 UTC, Steven Schveighoffer 
> On 5/23/18 9:59 AM, Alex wrote:
>> On Wednesday, 23 May 2018 at 13:49:45 UTC, Steven 
>> Schveighoffer wrote:
>>> Right, but not foreach(el1, el2; c), which is the equivalent 
>>> of your each call.
>> Yes. I tried this in the first place and get a compiler error. 
>> But it seemed logical to me, that if I define two opApply 
>> overloads, which both matches two arguments, then I need to 
>> specify which one I want to use. I achieved this by specifying 
>> the types inside the foreach... concisely enough for me :)
>> So... I'm looking how to do the same with ´each´, as defining 
>> the type of the lambda didn't help.
> In your example, you did not define the types for the lambda 
> (you used (a, b) => writeln(a, b) ). But I suspect `each` is 
> not going to work even if you did.

Yep. Tried this...

> In essence, `each` does not know what the lambda requires, 
> especially if it is a typeless lambda. So it essentially needs 
> to replicate what foreach would do -- try each of the 
> overloads, and if one matches, use it, if none or more than one 
> matches, fail.
> I suspect it's more complex, and I'm not sure that it can be 
> done with the current tools. But it's definitely a bug that it 
> doesn't work when you specify the types.
Ah... ok. Then, let me file a bug...

More information about the Digitalmars-d-learn mailing list