On Thu, 24 Feb 2011 02:39:36 -0500, Jonathan M Davis <[email protected]> wrote:

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.

The issue is not so much that the range is const or immutable, but that splitter uses IFTI to determine the parameter type. If splitter could use the tail-* version of itself when its argument was fully const or fully immutable, then it would work.

-Steve

Reply via email to