Const transitivity is bad sometimes

Jason House jason.james.house at gmail.com
Mon Jan 14 06:01:27 PST 2008


naryl wrote:

> For example, I have this piece of (useless) code:
> 
> http://paste.dprogramming.com/dpmmwnah
> 
> If there were more subscribers the same message would be sent to every one
> of them. And there may be several messages, carrying the same notifier as
> their data. While compiling this I got the following errors (DMD 2.009):
> 
> main.d(28): function main.SystemShutdownNotifier.addSubscriber
> (Subscriber) does not match parameter types (Subscriber)
> main.d(28): Error: (cmd.notifier).addSubscriber can only be called on a
> mutable object, not const(SystemShutdownNotifier)
> 
> I know. Notifier has become const because const is transitive, but in this
> example I don't need transitivity. I can't even think of a workaround for
> that. Maybe someone can help?

I think this is the classic sort of problem people have complained about
with const transitivity.  I don't know what people have suggested as the
workaround for this.  Personally, I've been thinking it'd be nice to mark
objects with something that says "I'll write to this, but will never read
from it".  


More information about the Digitalmars-d-learn mailing list