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
Wed May 25 04:31:13 PDT 2016


On Wednesday, 25 May 2016 at 11:14:26 UTC, FreeSlave wrote:
>
> Works with 'only', 'array' and static array slicing.
>
> import std.algorithm : map;
> import std.range : only;
> import std.conv : to;
> import std.stdio : writeln;
> import std.string : join;
> import std.array : array;
>
> string test(Args...)(in Args items){
>     immutable string[items.length] itemstrings = 
> map!(to!string)(only(items)).array;
>     return join(itemstrings[], ", ");
> }
>
> unittest{
>     writeln(test(1, 2, 3, 4));
> }

Nice, but I think it doesn't work with varying types.

writeln(test(1, 2, "v", 4, 'c'));


More information about the Digitalmars-d-learn mailing list