Immutable separator to join() doesn't work
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jul 12 02:10:03 PDT 2011
On Tuesday 12 July 2011 16:16:59 Daniel Murphy wrote:
> There is a fairly easy workaround that could be used throughout phobos:
> Accept T when isXXXRange!T || isXXXRange!(T[]), and use a static if to slice
> it when necessary. This would solve the problem for containers, static
> arrays, immutable arrays, and other immutable ranges.
I don't know whether that's a good idea for containers or const/immutable
arrays, but it _definitely_ is a bad idea for static arrays. It would end up
copying the entire array just because you forgot to slice it. Personally, I'm
_far_ more inclined to say that you should just expect to have to slice
something when you pass it to a range-based function. I think that the fact
that the "container" that gets most used at this point is the dynamic array
has gotten people used to not having to use slices much when proper containers
would require them. Since arrays are really slices, it errodes the line
between container and range, and I think that as proper containers are
completed in std.container and enter mainstream use, it's going to throw a lot
of people off, because they aren't going to function the quite same as arrays
(primarily due to the fact that a container and a range are not the same thing
with actual containers).
But regardless, while your suggestion might be a good idea in some cases, it's
definitely not a good solution for static arrays. And I'm skeptical that it's a
good idea in any case, but it would allow for immutable arrays to be used with
range-based functions. It would likely be better, however, to simply make it
so that slices of them can be used with range-based functions such as is the
case with static arrays.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list