Compiler bug? (alias sth this; and std.signals)
Joe
l0calh05t at gmx.net
Tue Nov 13 03:02:54 PST 2012
No one? Is this a bug, or am I overlooking something? (entirely
possible since I didn't use D since trying it once in D1 times)
On Monday, 12 November 2012 at 11:59:50 UTC, Joe wrote:
> Ok, i was trying out D and wanted to see if i could create
> something that behaves like a property but adds a change
> notification signal. Doing this, I encountered a hangup which
> might be a bug. So far I have the following:
>
> -----------------------------------------------------------
>
> import std.signals;
> import std.stdio;
>
> struct Property
> {
> alias get this;
>
> int set(int v) { emit(); return data_ = v; }
> int get() { return data_; }
>
> int opAssign(int v) { return set(v); }
>
> mixin Signal!();
>
> private:
> int data_ = 0;
> }
>
> struct Foo
> {
> Property prop;
> }
>
> class Observer
> {
> void watch()
> {
> writeln("Value change observed!");
> }
> }
>
> -----------------------------------------------------------
>
> This works:
> void main()
> {
> Foo f;
> Observer o = new Observer;
> f.prop.connect(&o.watch);
> f.prop = 7;
> }
>
> This also works:
> void main()
> {
> Foo f;
> Observer o = new Observer;
> f.prop = 7;
> writeln(f.prop);
> }
>
> This never terminates:
> void main()
> {
> Foo f;
> Observer o = new Observer;
> f.prop.connect(&o.watch);
> f.prop = 7;
> writeln(f.prop);
> }
More information about the Digitalmars-d
mailing list