On Sunday, 31 May 2015 at 07:28:02 UTC, Ali Çehreli wrote:
So, you want to skip that extra func() call and have the code
be "inlined". That's one of the things what any decent
optimizing compiler does anyway.
Yes, I think that there is an extra function call, because DMD is
based on Zortech C++ backend, so I figured ... :)
I hear great things especially about ldc and that gdc is just
good enough. Of course, one needs to check the assembly output
to be sure that there is no extra function calls.
Ali
And yet in DMD I'm not sure :)
import std.stdio, std.algorithm;
static int idx;
void walk(R)(R range) {
while (!range.empty) {
range.front;
range.popFront;
}
}
struct Tap(alias func, R)
{
R range;
alias range this;
@property auto front()
{
func(range.front);
return range.front;
}
}
auto tap(alias func, R)(R range)
{
writeln(__FUNCTION__); // ???
return Tap!(func, R)(range);
}
void main() {
[5, 6, 7]
.map!(a => [idx++, a])
.tap!((a) { writeln(a[1..$]); })
.walk;
}