Immutable separator to join() doesn't work

Daniel Murphy yebblies at nospamgmail.com
Mon Jul 11 23:16:59 PDT 2011


"Jonathan M Davis" <jmdavisProg at gmx.com> wrote in message 
news:mailman.1554.1310450510.14074.digitalmars-d at puremagic.com...
> Nope. It works for static arrays but not for const or immutable arrays. 
> Try
> it. It'll fail. I don't know _why_ it doesn't work, but it doesn't. If it 
> did,
> this would be a much smaller issue. It would be nice if templates were
> improved such that they instantiated range-based functions in a manner 
> which
> worked for static arrays and const or immutable arrays, but if you could 
> solve
> the problem by slicing a const or immutable array, it would make the 
> situation
> far less problematic.
>
> - Jonathan M Davis

Yeah, looking at the implementation and the test cases that rely on this, it 
seems to have been done to allow slicing typedefs to yeild the same type.  I 
really doubt this is something we need to support any more.
Every time this issue came up, I've always assumed this was how it worked!
Honestly, template deduction with implicit conversions is very unlikely to 
ever happen.  While it looks nice for one parameter, it quickly turns into a 
huge mess for multiple parameters.

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. 




More information about the Digitalmars-d mailing list