Challenge

rsw0x via Digitalmars-d digitalmars-d at puremagic.com
Sun Aug 30 03:30:01 PDT 2015


On Sunday, 30 August 2015 at 10:21:20 UTC, rsw0x wrote:
> 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?

Oh, I think I see what you were asking. It doesn't compile with 
LDC, but it compiles just fine with latest DMD.
hmm


More information about the Digitalmars-d mailing list