On Sunday, 30 August 2015 at 10:15:14 UTC, John Colvin wrote:
import std.algorithm, std.range;
auto foo(R)(R a, immutable int b)
{
return a.map!(x => x + b);
}
unittest @nogc @safe
{
int[] test = [1,2,3];
assert(test.foo(3).equal(only(4,5,6)));
}
Challenge: reimplement `foo` such that above unittest will
compile. No cheating with malloc etc. Bonus points if you don't
have to implement a modified version of std.algorithm.map
import std.algorithm, std.range;
auto foo(R)(R a, immutable int b)
{
return a.map!(x => x + b);
}
@nogc @safe unittest
{
int[3] test = [1,2,3];
assert(test[].foo(3).equal(only(4,5,6)));
}
does this count?