On Sunday, 16 August 2015 at 12:30:54 UTC, cym13 wrote:
On Sunday, 16 August 2015 at 11:53:42 UTC, FreeSlave wrote:
[...]
Ok, so as my lambda proposition obviously doesn't work, here is
one way that does using a templated function. There may be a
way to make it shorter, I don't know.
import std.conv;
import std.stdio;
template fun(uint context) {
static uint withContext(uint value) {
return value * context;
}
auto fun(uint[] arr) @nogc {
return arr.map!withContext;
}
}
void main(string[] args) {
[1, 2, 3].to!(uint[])
.fun!2
.writeln;
}
It works only because 2 is known constant at compile time.