How to foreach over a DList?

monarch_dodra monarchdodra at gmail.com
Tue Apr 1 05:30:01 PDT 2014


On Tuesday, 1 April 2014 at 10:56:40 UTC, Ali Çehreli wrote:
> On 03/31/2014 10:32 PM, Jeroen Bollen wrote:
>> Still no luck:
>>
>> import std.container;
>> import std.stdio;
>>
>> void main()
>> {
>>     DList!ubyte list1 = DList!ubyte();
>>     list1 ~= cast(ubyte) 1;
>>     list1 ~= cast(ubyte) 2;
>>     list1 ~= cast(ubyte) 3;
>>
>>     foreach(ubyte item; list1[]) {
>>         writeln(item);
>>     }
>> }
>>
>> /usr/include/dlang/dmd/std/container.d(1874): Error: no 
>> property
>> '_first' for type 'ubyte'
>> /usr/include/dlang/dmd/std/container.d(1875): Error: no 
>> property
>> '_first' for type 'ubyte'
>> /usr/include/dlang/dmd/std/container.d(1875): Error: undefined
>> identifier rhs_, did you mean variable rhs?
>> source/app.d(7): Error: template instance
>> std.container.DList!ubyte.DList.opOpAssign!("~", ubyte) error 
>> instantiating
>> source/app.d(7): Error: cannot append type ubyte to type 
>> DList!ubyte
>
> I think your problem is fixed in a more recent compiler. The 
> code works with git head dmd but fails with e.g. 2.064. (Not 
> tested with 2.065.)
>
> Ali

I fixed this not too long ago. Long story short, the "~=" 
implementations were made of fail.

Just change those "~=" for "insertBack" and you should be fine.


More information about the Digitalmars-d-learn mailing list