D has two types of constness: immutable variables are ones that were declared immutable, and always will be immutable, while const variables are simply rea
Being a pragmatic language, D has the ability to cast away const if you really need to. I think the following should work:
class M { bool set; real val; real D() const { if(!set) { M m = cast(M)this; m.val = this.some_fn(); m.set = true; } return this.val; } }