On Thursday 13 January 2011 21:21:06 %u wrote: > Hi, > > I've noticed that some functions, such as algorithm.endsWith, don't work > with constant arrays. Is this a bug, or is there a reason behind it? It > forces the user to perform dangerous casts to avoid object creation, and > it doesn't seem like the functions actually need to perform any > manipulations.
Phobos doesn't really deal with const or immutable correctly at this point. A number of things which should be able to handle const or immutable can't. And then there are things which you'd think _should_ be able to but can't because of the transivity of const and immutable. There are a number of outstanding bugs related to const and immutable which makes dealing with them at times a bit of a pain if not outright impossible. It's on the list of things to be focused on after the 64-bit port of dmd is done. As it stands, there are a number of algorithms which just won't work with const or immutable arrays. 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. - Jonathan M Davis
