digitalmars.D.learn - Using TreeSet and __gshared values
- nrgyzer (49/49) Sep 03 2014 Hi guys,
- ketmar via Digitalmars-d-learn (13/13) Sep 03 2014 On Wed, 03 Sep 2014 19:53:15 +0000
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (4/11) Sep 04 2014 Hmm... would be nice if there were a warning/error when __gshared
- ketmar via Digitalmars-d-learn (3/5) Sep 04 2014 would you fill enhancement request in bugzilla?
- "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> (3/9) Sep 04 2014 https://issues.dlang.org/show_bug.cgi?id=13421
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?
Sep 03 2014
On Wed, 03 Sep 2014 19:53:15 +0000
nrgyzer via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
wrote:
__gshared class members are effectively "static", i.e. they are "class
members", not "instance members".
i.e.
class Entry {
__gshared int value;
...
static int getValue () { return value; }
}
works ok.
you have only one 'value' variable for all your instances.
Sep 03 2014
On Wednesday, 3 September 2014 at 20:10:51 UTC, ketmar via Digitalmars-d-learn wrote:On Wed, 03 Sep 2014 19:53:15 +0000 nrgyzer via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote: __gshared class members are effectively "static", i.e. they are "class members", not "instance members".Hmm... would be nice if there were a warning/error when __gshared is used without static in a class.
Sep 04 2014
On Thu, 04 Sep 2014 08:38:50 +0000 via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:Hmm... would be nice if there were a warning/error when __gshared=20 is used without static in a class.would you fill enhancement request in bugzilla?
Sep 04 2014
On Thursday, 4 September 2014 at 09:02:26 UTC, ketmar via Digitalmars-d-learn wrote:On Thu, 04 Sep 2014 08:38:50 +0000 via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:https://issues.dlang.org/show_bug.cgi?id=13421Hmm... would be nice if there were a warning/error when __gshared is used without static in a class.would you fill enhancement request in bugzilla?
Sep 04 2014








"Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net>