Head Const
ZombineDev via Digitalmars-d
digitalmars-d at puremagic.com
Mon Feb 15 15:11:51 PST 2016
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.
I'll leave to others to discuss whether a language solution is
worth it, but I just wanted to point out there are two library
solutions in this area:
HeadConst [1] - PR pending, and
Rebindable (tail const) [2] - already part of Phobos.
Maybe if the language could express head const, it also makes
sense to have tail const.
[1]: https://github.com/D-Programming-Language/phobos/pull/3862
[2]:
http://dlang.org/phobos-prerelease/std_typecons.html#.Rebindable
More information about the Digitalmars-d
mailing list