digitalmars.D - D1 & D2 discrepancy
- lanael (68/68) Dec 23 2011 The following piece of code compiles without error on D1(1.072) &
- Trass3r (1/10) Dec 23 2011 Looks suspicious. Debug it to see what gets called.
- =?UTF-8?B?xYF1a2FzeiBXcnpvc2Vr?= (2/16) Dec 23 2011 writefln should be replaced with writeln and it works on d2 too.
- Jesse Phillips (3/4) Jan 02 2012 D1 does not have a writeln function:
The following piece of code compiles without error on D1(1.072) &
D2(2.057).
However the D2 version doesn't run fine. ( output below )
---------------------------->8----------------------------
abstract class Receiver(M) {
this() { Broadcaster!(M).register(this); }
~this() { Broadcaster!(M).unregister(this); }
abstract void onMessage( M message );
}
abstract class Emitter(M) {
void emit(M message) { Broadcaster!(M).broadcast(message); }
}
static class Broadcaster(M) {
private static Receiver!(M)[string] mReceivers;
public static void register( Receiver!(M) receiver ) {
mReceivers[receiver.toString()] = receiver;
}
public static void unregister( Receiver!(M) receiver ) {
mReceivers.remove(receiver.toString());
}
public static void broadcast( M message ) {
foreach( ref receiver; mReceivers ) {
receiver.onMessage( message );
}
delete message;
}
}
//================================================== import
std.stdio;
void main() {
class TestMessage {
this( string m ) { stringAttribute = m; }
string stringAttribute;
}
class TestReceiver1: Receiver!(TestMessage) {
this() { super(); }
override void onMessage( TestMessage m ) {
writefln( "receiver 1 :", m.stringAttribute );
}
}
class TestReceiver2: Receiver!(TestMessage) {
this() { super(); }
override void onMessage( TestMessage m ) {
writefln( "receiver 2 :", m.stringAttribute );
}
}
class TestEmitter: Emitter!(TestMessage) {
void send() {
emit( new TestMessage("Hey") );
}
}
auto e = new TestEmitter;
auto r1 = new TestReceiver1;
auto r2 = new TestReceiver2;
e.send;
delete r2;
e.send;
}
----------------------------8<----------------------------
* Output of the D1 version :
receiver 1 :Hey
receiver 2 :Hey
receiver 1 :Hey
* Output of the D2 version :
receiver 1 :
receiver 2 :
receiver 1 :
Is this a bug or something stupid on my part ?
Dec 23 2011
* Output of the D1 version : receiver 1 :Hey receiver 2 :Hey receiver 1 :Hey * Output of the D2 version : receiver 1 : receiver 2 : receiver 1 : Is this a bug or something stupid on my part ?Looks suspicious. Debug it to see what gets called.
Dec 23 2011
W dniu 23.12.2011 14:37, Trass3r pisze:writefln should be replaced with writeln and it works on d2 too.* Output of the D1 version : receiver 1 :Hey receiver 2 :Hey receiver 1 :Hey * Output of the D2 version : receiver 1 : receiver 2 : receiver 1 : Is this a bug or something stupid on my part ?Looks suspicious. Debug it to see what gets called.
Dec 23 2011
On Sat, 24 Dec 2011 01:45:56 +0100, Ćukasz Wrzosek wrote:writefln should be replaced with writeln and it works on d2 too.D1 does not have a writeln function: http://digitalmars.com/d/1.0/phobos/std_stdio.html
Jan 02 2012








Jesse Phillips <jessekphillips+d gmail.com>