On the point of "not possible...", "only a symbol...", etc:

T* ptrCast(T, alias ptr)() { return cast(T*)ptr; }

void addInt(void* state, void* data)
{
    alias _state = ptrCast!(int, state);
    alias _data = ptrCast!(int, data);

    static assert(!is(typeof(_state) == int*));
    static assert(!is(typeof(_data) == int*));

    *_state += *_data;
}

But take heed to the compiler optimization advice. DMD generates pretty horrendous code for this. LDC does rather well though. Since speed matters, always look at the assembly. Look at it even if it doesn't ;)

Reply via email to