On Monday, 14 May 2012 at 16:53:24 UTC, Timon Gehr wrote:
On 05/14/2012 06:10 AM, Chris Cain wrote:
On Monday, 14 May 2012 at 02:57:57 UTC, Mehrdad wrote:
The problem is that it's unavoidable.

i.e. you can't say "don't mark it as const if it isn't const",
because, practically speaking, it's being forced onto the programmers
by the language.

You're really against const in this language, huh?


I guess this is not the most important point.
He has been trying to use const like in OO-ish C++.
This just does not work, because D const is detrimental to OO
principles when used that way.
The proposal is about _enforcing_ C++-like usage of const.

but c++ has the 'mutable' keyword as an easy escape route... which saved me a bunch of times... guess one can emulate it with a library-solution using nested classes? But... what about structs?

class Outer
{
  int i = 6; // mutable

  class Inner {
    int y=0;

    int foo() const
    {
      // ++y; // fail
      return ++i; // look ma, mutable const
    }
  }
  Inner inner;
  this()
  {
    inner = new Inner;
  }
  alias inner this;
}

Reply via email to