D Paste by naryl
Description: "Workaround" for transitive const
Hide line numbers

Create new paste
Post a reply
View replies

Paste:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
module main;

class SystemShutdownNotifier {

    Subscriber[] subscribers;

    void addSubscriber(Subscriber subscriber) {
        subscribers ~= subscriber;
    }
}

interface Message {
}

class MsgShutdownNotifierStarted: Message {
    public:
        this(SystemShutdownNotifier notifier_) {
            this.notifier_ = notifier_;
        }

        SystemShutdownNotifier notifier(SystemShutdownNotifier notifier_) {
            return this.notifier_ = notifier_;
        }

        const SystemShutdownNotifier notifier() {
            return cast(SystemShutdownNotifier) notifier_;
        }

    private:
        SystemShutdownNotifier notifier_;
}

class Subscriber {
    public:
        void onShutdownNotifierStarted(const(MsgShutdownNotifierStarted) cmd) {
            cmd.notifier.addSubscriber(this);
        }
}

void main() {
    auto subscriber = new Subscriber();

    auto notifier = new SystemShutdownNotifier();

    invariant message = cast(invariant) (new MsgShutdownNotifierStarted(
            notifier));

    subscriber.onShutdownNotifierStarted(message);
}

Replies:

    (some replies deleted)