On Thursday, 13 June 2013 at 12:29:57 UTC, Simen Kjaeraas wrote:
On Thu, 13 Jun 2013 14:17:22 +0200, Stephan Schiffels <stephan_schiff...@mac.com> wrote:

For example, is there a way of instantiating an object normally (i.e. mutable), and then later "freeze" it to immutable via a simple cast or so?

In std.exception there is assumeUnique. It's basically just a cast, but
might be good enough for you.

Is there any other recourse here?

Why does making `this(...) immutable` fix things below?
Shouldn't that immutable designation mean no members of this will be modified? But that is the whole point of an initializer? Why does immutable make sense in this context at all?

My problem is a bit more elaborate and unfortunately to initialize members I need to call standard functions that have not been made pure (but should be).



struct T {
  int[] i;
}

struct S {
  int[] i;
  immutable T t;
  this(immutable T _t) {
    t = _t;
  }
}

void main() {
  auto t = immutable T();
  auto s = immutable S(t);
}

Reply via email to