User defined type and foreach
Tony
tonytdominguez at aol.com
Fri Nov 17 01:06:31 UTC 2017
On Thursday, 16 November 2017 at 18:34:54 UTC, Steven
Schveighoffer wrote:
> On 11/16/17 8:10 AM, ag0aep6g wrote:
>> On 11/16/2017 09:03 AM, Tony wrote:
>>> However, when I use the class with foreach, the opindex gets
>>> called to create a dynamic array, rather than use the
>>> empty(),front(),popFront() routines. I would prefer it use
>>> the three methods, rather than create a dynamic array.
>>
>> https://issues.dlang.org/show_bug.cgi?id=14619
>
> I took a shot at fixing. Way more complex than I realized.
>
I was initially miffed that I had added empty(), popFront() and
pop() and they weren't being used, but I don't have a problem
with using [] instead of them. Maybe call it a feature and
document it.
But I do have a complaint about the methods empty(), popFront()
and pop(). I think they should have a special syntax or name to
reflect that they are not general purpose methods. __empty() or
preferably __forEachDone(). empty() is typically used to say if
a container has no data, not if you are at the end of external
foreach loop processing. pop() and popFront() also would
typically have different meanings with certain containers and
their names don't reflect that they have a special "external
foreach loop" purpose.
More information about the Digitalmars-d-learn
mailing list