cast_util: Add FptrCast

Reduce unnecessary type duplication when casting a lambda to a function pointer.
This commit is contained in:
MerryMage 2020-04-04 10:57:41 +01:00
parent fe583aa076
commit bd88286b21
7 changed files with 38 additions and 26 deletions

View file

@ -9,6 +9,8 @@
#include <cstring>
#include <type_traits>
#include <mp/traits/function_info.h>
namespace Dynarmic::Common {
/// Reinterpret objects of one type as another by bit-casting between object representations.
@ -35,4 +37,10 @@ inline Dest BitCastPointee(const SourcePtr source) noexcept {
return reinterpret_cast<Dest&>(dest);
}
/// Cast a lambda into an equivalent function pointer.
template <class Function>
inline auto FptrCast(Function f) noexcept {
return static_cast<mp::equivalent_function_type<Function>*>(f);
}
} // namespace Dynarmic::Common