Using TreeSet and __gshared values

nrgyzer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Sep 3 12:53:15 PDT 2014


Hi guys,

I'm having some trouble using the treeset implementation of
Steven (dcollections) in conjunction with __gshared. When I do
the following:

class Entry
{
	int value;
	this(int v)
	{
		value = v;
	}
	int opCmp(Object o)
	{
		return -1;
	}
}

void main()
{

	auto tree = new TreeSet!Entry();
	tree.add(new Entry(10));
	tree.add(new Entry(20));
	tree.add(new Entry(30));

	foreach (ref entry; tree)
	{
		writeln(entry.value);
	}
}

I'm getting the following output:

10
20
30

But when I replace the class as follows:

class Entry
{
	__gshared int value;
	this(int v)
	{
		value = v;
	}
	int opCmp(Object o)
	{
		return -1;
	}
}

I'm getting the following output:

30
30
30

Do anyone have any ideas what can cause the problem?


More information about the Digitalmars-d-learn mailing list