---- import std.algorithm : map; import std.range : isInputRange, ElementType; // Doesn't work //template deepMap(alias pred, Range) //if(isInputRange!Range) //{ // static if(isInputRange!(ElementType!Range)) // { // alias deepMap = map!(a => deepMap!(pred, typeof(a))(a)); // } // else // { // alias deepMap = map!(pred); // } //} // Neither does this, for the same reason auto deepMap(alias pred, Range)(Range r) if(isInputRange!Range) { static if(isInputRange!(ElementType!Range)) { return r.map!( a => a.deepMap!(pred)() )(); } else { return r.map!(pred)(); } } unittest { import std.stdio; auto a = [[1, 1], [1, 1]]; auto b = a.deepMap!(a => a + 1)(); writeln(b); //assert(b == [[2, 2], [2, 2]]); } ----
DPaste has stopped responding to requests at the time of writing,
so here's the code in case its still down by the time someone
reads this:
- Compiler errors and recursive nested functions Dylan Knutson
- Re: Compiler errors and recursive nested functions Ali Çehreli
- Re: Compiler errors and recursive nested functions Dylan Knutson