const - Best practices
Jonathan M Davis
jmdavisProg at gmx.com
Sat Dec 31 13:13:24 PST 2011
On Saturday, December 31, 2011 08:02:52 Caligo wrote:
> On Sun, Jan 2, 2011 at 4:43 PM, Jonathan M Davis <jmdavisProg at gmx.com>wrote:
> > - Jonathan M Davis
>
> Almost a year has passed, and what is the state of const now? Is it still
> broken? I've been reading some threads on SO, and I'm a bit confused as to
> what's correct in my code and what's not.
Progress has definitely been made. inout finally works. Dynamic arrays are being
changed to instantiate as tail-const with IFTI, so templated functions in
Phobos will do much better with const (I think that the change is in github
but not released yet; if not, it should be on github soon). A number of bugs
have been fixed as well. But not everything has been sorted out yet. I believe
that the two biggest issues are
1. Const-correctness. We have pull requests to fix this which are under
discussion, but due to some of the non-trivial implications of the changes,
they haven't been merged in yet.
2. Postblit constructors don't work with const or immutable (which makes a
fair bit of sense when you consider how they work by memcpying and then
changing the state of the copy). Walter and Andrei supposedly have a solution,
but they haven't revealed what it is yet, let alone implemented it.
So, the situation is definitely better than it was, and const is quite usable
in plenty of circumstances, but there are still definitely outstanding issues
which need to be resolved. Fortunately however, solutions for them _are_ in
the works.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list