Making RCSlice and DIP74 work with const and immutable
Jakob Ovrum via Digitalmars-d
digitalmars-d at puremagic.com
Sun Mar 1 07:49:11 PST 2015
On Sunday, 1 March 2015 at 15:40:06 UTC, Atila Neves wrote:
> I've lost count now of how many times I've had to downgrade to
> auto despite always wanting immutable or const. This doesn't
> work:
>
> auto reg = regex(`(foo)`);
> const match = "foo".matchAll(reg);
> writeln(match.captures); //oops, captures isn't const
>
> It should, but it doesn't. Maxime talked about it here as well:
>
> http://pointersgonewild.com/2014/07/11/the-constness-problem/
>
> Atila
`match.captures` is a range; it's only natural for a range to
have mutable state to be iterable.
D's const is a bridge between immutable and mutable. const has to
be transitive because immutable is transitive. Don't use it as if
it was C++ const: there's no logical const in D, and if there
ever will be, it can't use the same `const` type qualifier.
More information about the Digitalmars-d
mailing list