On Sunday, 22 July 2012 at 13:04:18 UTC, David Nadlinger wrote:
I hit some of the problems you described a little while ago. Jonathan and I came to the conclusion that the best solution is to default to the same element type as the passed range, while allowing any type which the element type is convertible to to be specified via an extra template parameter, just as you proposed.

I have a half-finished version (sans handling of narrow strings) lying around, but won't have time to polish it up for inclusion in the next few weeks, so feel free to go ahead.

David

Yeah, I saw your posts regarding that. I hope I won't hit any problems with my implementation.

What about

import std.conv: to;
auto integralThirds = iota(1,20).map(a => to!int(a/3)).array;

?

It even allows converting to strings, which is something I do very often.

While I won't argue the result is not the same, the intent is not as clear (IMO).

Suppose the function I wanted to apply was not anonymous, but "foo":

Your approach:
auto ints = iota(1,20).map(a => to!int(foo(a))).array;
or
auto ints = iota(1,20).map(foo).map(a => to!int(a)).array;

Which (IMO) really doesn't quite translate the intent as well as:
auto ints = iota(1,20).map(foo).array!int;

----
I think the bottom line about array is that it requires trivial simplicity.

Reply via email to