Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 20, 2006 list21.backwards | ||||
---|---|---|---|---|
| ||||
I'm playing with lists as an alternative to arrays and have come across a problem: module people; private import std.stdio; private import list; class Person { mixin List; // Turn the Person class into a linked list. char[] name,tname; ubyte age; this(char[] name, ubyte age){this.name = name;this.age = age;} } int main() { Person.ListHead people,others; foreach(Person p; people.each) { writefln("Person %s is %d years old", p.name, p.age); } writefln("---"); foreach(Person p; others.each.backwards) { writefln("Person %s is %d years old", p.name, p.age); } return 0; } produces: C:\list21>testing6 --- Error: Access Violation C:\list21> So iterating over a list is OK provided you don't try to reverse it. I'm guessing this is an error in the library but not sure how to fix it. Anyone got an idea? Simon |
June 21, 2006 Re: list21.backwards | ||||
---|---|---|---|---|
| ||||
Posted in reply to simon.hodson | On Tue, 20 Jun 2006 12:36:20 -0400, <simon.hodson@hssnet.com> wrote: > So iterating over a list is OK provided you don't try to reverse it. I'm > guessing this is an error in the library but not sure how to fix it. Anyone got > an idea? > > Simon A fixed version is uploaded to http://www.dprogramming.com/list.php - thanks for letting me know about this. It was only an issue in a contract (debug only). |
June 21, 2006 Re: list21.backwards | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Miller | Thanks Chris,
I've found another similar assert issue where a filter is applied against an empty list and then the list be sorted backwards: -
module people;
private import std.stdio;
private import list;
class Person
{
mixin List; // Turn the Person class into a linked list.
char[] name,tname;
ubyte age;
this(char[] name, ubyte age){this.name = name;this.age = age;}
}
int main()
{
Person.ListHead people,others;
writefln("-start filter-");
others.filter(
delegate bool(Person f)
{
if(f.name is null)
{
others.remove(f);
}
return true;
}
);
writefln("-end filter-");
foreach(Person p; others.each.backwards)
{
writefln("Person %s is %d years old", p.name, p.age);
}
return 0;
}
produces: -
C:\list21>testing6
-start filter-
Error: AssertError Failure list.d(648)
Regards
Simon
In article <op.tbhrcyuppo9bzi@moe>, Chris Miller says...
>
>On Tue, 20 Jun 2006 12:36:20 -0400, <simon.hodson@hssnet.com> wrote:
>> So iterating over a list is OK provided you don't try to reverse it. I'm
>> guessing this is an error in the library but not sure how to fix it.
>> Anyone got
>> an idea?
>>
>> Simon
>
>A fixed version is uploaded to http://www.dprogramming.com/list.php - thanks for letting me know about this. It was only an issue in a contract (debug only).
|
June 21, 2006 Re: list21.backwards | ||||
---|---|---|---|---|
| ||||
Posted in reply to simon.hodson | On Wed, 21 Jun 2006 10:49:29 -0400, <simon.hodson@hssnet.com> wrote:
> I've found another similar assert issue where a filter is applied against an
> empty list and then the list be sorted backwards: -
Thanks, updated.
|
Copyright © 1999-2021 by the D Language Foundation