Challenge
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Sun Aug 30 03:38:28 PDT 2015
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
Ok, so now I feel stupid. Not only was the unittest I gave above
broken anyway, I realised what my underlying problem was within
minutes of posting...
Carry on, nothing to see here...
More information about the Digitalmars-d
mailing list