What's wrong with my usage of std.algorithm.map in this code example?
Chris via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu May 26 01:38:05 PDT 2016
On Wednesday, 25 May 2016 at 19:07:32 UTC, Era Scarecrow wrote:
> On Wednesday, 25 May 2016 at 13:27:28 UTC, Chris wrote:
>> Why can the tuple be iterated with foreach, as in my quick
>> fix, and indexed with tuple[0..], but is not accepted as a
>> range? What are the differences? Is there a way to rangify a
>> tuple?
>
> The tuple is identified/used at compile-time, as such it's a
> compiler primitive and not a range. Foreach in this case will
> unroll the loop regardless how it looks. So...
>
> test(Args...)(Args args) {
> ...
> foreach (const ref i; items)
> itemstrings ~= i.to!string;
>
> Will become: (const and ref are pointless in this example,
> unless the args are referenced)
>
> test(int arg1, int arg2, int arg3, int arg4) {
> ...
> itemstrings ~= arg1.to!string;
> itemstrings ~= arg2.to!string;
> itemstrings ~= arg3.to!string;
> itemstrings ~= arg4.to!string;
>
>
> Trying to use map on it was literally expanding the entire
> input to map.
Ah, I didn't know that it was just unrolled. That makes sense, of
course.
[snip]
More information about the Digitalmars-d-learn
mailing list