On Tuesday, 16 February 2016 at 09:39:31 UTC, Sönke Ludwig wrote:
Am 16.02.2016 um 08:20 schrieb Ola Fosheim Grøstad:
On Monday, 15 February 2016 at 22:48:16 UTC, Walter Bright wrote:
rears its head again :-)

Head Const is what C++ has for const, i.e. it is not transitive,
applies to one level only. D has transitive const.

What head const will do for us:

1. make it easy to interface to C++ code that uses const, as currently it is not very practical to do so, you have to resort to pragma(mangle)

2. supports single assignment style of programming, even if the data
is otherwise mutable

The downside is, of course, language complexity.

Maybe you can get away with adding "mutable", which is needed for
intrusive ref counting as well:

C++:
Type * const ptr;

struct ConstType {
mutable int rc;
}


D:
const mutable(Type)* ptr;

struct ConstType {
mutable(int) rc;
}

As a bonus, this would also provide a natural syntax to define tail-const class references:

mutable const(C) something;

Another bonus to introducing the mutable keyword is the option to make everything immutable by default (in a future version of D) and allow the users to have mutable objects only if they use the mutable keyword.

Reply via email to