On Sunday, 14 May 2017 at 21:07:36 UTC, Marco Leise wrote:
Am Sun, 14 May 2017 20:18:24 +0000
schrieb Kevin Brogan <ke...@brogan.ca>:
[...]
No, that is not possible. An alias can only be assigned a
symbol.
[...]
Let the compiler optimize the assignment away and don't worry
much about it. Inlining also works well within the same module.
In this case here I would probably use "consume" functions as I
dub them:
import std.traits;
pragma(inline, true) /* Not really needed I hope ;) */
ref T consume(T)(ref void* data) if (!hasIndirections!T)
{
T* ptr = cast(T*)data;
data += T.sizeof;
return *ptr;
}
You can then rewrite your addInt function like this:
void add(T)(void* state, void* data) if (isNumeric!T)
{
state.consume!T += data.consume!T;
}
pragma(inline, true); doesn't actually do what you think it does.
In lining is always done whenever possible and that only tells
the compiler to spit out an error if it can't inline it.