You are extremely lucky - a video from DConf2013 with presentation devoted exactly to this topic has been published last week : http://youtu.be/mPr2UspS0fE
In your case, auto s = new immutable(S)();
should do the trick. You can then create data slice points to in constructor. However, if this slice may point to any data, then S can't possibly be immutable, because both const
and immutable
are transitive in D - they provide very strong guarantees not only about variable itself but also about any data that can be accessed from it indirectly via reference/pointer.
It is actually covered in linked video, but short summary is that you want to use immutable when really intend to. In other words, when you want your code to break if S
implementation changes so that immutable guarantees are no longer valid.