On Sunday, 14 May 2017 at 21:16:04 UTC, Stanislav Blinov wrote:
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;
}

That's a pretty cool workaround, but not an alias to the cast, but an alias to a parametrized function template (a type), so I will stick to my statement of "not possible". AFAIK, this would also invoke the respective function template instance for ptrCast every time _state or _data are referenced, so if we're going with the spirit of the question that's still going to be horrible if the compiler doesn't optimize ;p

Reply via email to