Closed virtuald closed 3 years ago
This is what I have:
template<typename T>
concept function_pointer = std::is_pointer_v<T> && std::is_function_v<std::remove_pointer_t<T>>;
template<function_pointer T>
LONG attach(T &function, std::type_identity_t<T> detour) noexcept
{
return DetourAttach(reinterpret_cast<void **>(&function), reinterpret_cast<void *>(detour));
}
Do you have a pre-C++20 version of that?
@virtuald sounds reasonable to me, we would appreciate that contribution. As you mentioned, having it be under an appropriate c++ version check would be important.
See #178
Idea: add a DetourAttachSafe (or better name since it's not really safer... ) to make it easier to determine if your detour attach is incorrect. Because of the void* casts often needed, we've sometimes gotten tripped up by not using the correct pointers.
Would require C++11, but you could surround the function with an
#ifdef
to not interfere with C compilers or older C++ compilers.Here's an example of the type-checking in action (note: I haven't actually used this in conjunction with detours yet, was played around with it on Godbolt).
If this would be accepted, I can make a PR at some point and actually try it out.