On 9/24/2011 7:31 PM, Jonathan M Davis wrote:
Well I suppose that it's a matter of semantics, but it's _not_ valid code,
because D's const is not a logical const and does not support logical const in
any way.

I think that's the gist of it. Logical const is NOT CONST in D.


The problem is the fact that there is no way in D to express the
particular paradigm that you want to express - logical const.

There is:

struct LogicalConst(T)
{
    @property T v() {
       if (!set) {
          _v = some_expensive_computation();
          set = true;
       }
       return _v;
    }

  private:
    bool set = false;
    T _v;
}

Granted, that's a different way of doing it than C++ does it, but it is perfectly doable. It doesn't do anything dirty, unsafe, or underhanded. It isn't a fraud. It's even typesafe.

Reply via email to