Splitter.opSlice(), ranges and const strings
Jonathan M Davis
jmdavisProg at gmx.com
Wed Feb 23 23:39:36 PST 2011
On Wednesday 23 February 2011 22:41:53 Christopher Bergqvist wrote:
> Hi!
>
> I've run into an issue which I don't understand.
>
> Boiled down code:
> import std.regex;
>
> void main()
> {
> //string str = "sdf"; // works
> //const string str = "sdf"; // doesn't work
> immutable str = "sdf"; // doesn't work
> auto pat = regex(", *");
> auto split = splitter(str, pat);
> }
>
> Error:
> /Library/Compilers/dmd2/osx/bin/../../src/phobos/std/regex.d(3022):
> Error: this is not mutable
>
> Should splitter() be able to cope with const/immutable ranges?
>
> (That's with the latest official v2.052 dmd/phobos distribution for
> mac. I got the same error before upgrading from the v2.051
> also).
Pretty much _nothing_ copes with const or immutable ranges. And if you think
about it, it generally makes sense. You can't pop the front off of a const or
immutable range. So, how could you possibly process it? The are some cases where
having tail const with ranges would work (assuming that we could have tail const
with ranges - which we currently can't), but on the whole, const and immutable
ranges don't really make sense. They can hold const or immutable data, but a
const or immutable range is pretty useless on the whole.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list