[Issue 11082] std.algorithm.join of a dynamic array of fixed-size arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Sep 21 11:36:15 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11082



--- Comment #6 from Peter Alexander <peter.alexander.au at gmail.com> 2013-09-21 11:36:14 PDT ---
(In reply to comment #5)
> (In reply to comment #4)
> 
> > You'd have to special case algorithms to handle them, because
> > they violate the range API by their very nature.
> 
> Right, I am asking for a specialization of join. It's worth doing.

But is it worth doing for every other algorithm, and every container type? If
not, why not? If so, I'd say that's too much to ask.


> > And it's trivial enough to
> > slice static arrays - even when they're inside a dynamic array -
> 
> This code is buggy:
> 
> import std.algorithm: join;
> import std.stdio, std.algorithm;
> void main() {
>     int[2][] data = [[1, 2]];
>     data.map!q{ a[] }.join.writeln;
> }

You have to do:

data.map!((ref a => a[])).join.writeln;

Unfortunately shorthand lambdas and unaryFun default to pass-by-value, so you
get a stack copy of your static array, which you then slice just as it goes out
of scope.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list