On Fri, 14 Jan 2011 02:21:03 -0500, %u <[email protected]> wrote:

Regardless, a fully const array is never going to work with a function like
endsWith() for the simple reason that such functions have to actually be able to process the range that they're given, and if the range is const, you can't call
popFront() or popBack() on it, so it just isn't going to work.
Now, if you take a _slice_ of a const array, it should work, because while the
elements of the array will remain const, the slice itself won't be, so endsWith()
can process it.

The issue is that IFTI uses exactly the type used to call it.

void foo(T)(T t)
{
   writeln(typeid(T));
}

const(int[]) x = [1,2,3];
foo(x); // prints const(int[])

What you really want is for IFTI to strip down const/immutable on arrays and basic types. I think it's a bugzilla bug somewhere, if not it's definitely been discussed on the phobos mailing list.


I see what's happening, but the problem with slicing is that it doesn't prevent a resize of the array, which, if not allocated with GC memory, could break code. How can you have a non-resizeable slice, while still maintaining the constness of an
array? Is that even possible?

Since 2.041, this cannot happen. A resize of a slice where data will be overwritten from the original array always results in a reallocation.

-Steve

Reply via email to