Skip to content

Commit b662d58

Browse files
committed
Add GetVirtualIndex function by typed signature
1 parent 75aab41 commit b662d58

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

include/dynlibutils/virtual.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
namespace DynLibUtils {
2222

23-
template<auto METHOD>
23+
template<typename F, F METHOD>
2424
constexpr std::ptrdiff_t GetVirtualIndex() noexcept
2525
{
26-
static_assert(std::is_member_function_pointer_v<decltype(METHOD)>, "Templated method must be a pointer-to-member-function");
26+
static_assert(std::is_member_function_pointer_v<F>, "Templated method must be a pointer-to-member-function");
2727

2828
// --- Itanium C++ ABI: PMF.ptr = 1 + offset_in_bytes for virtual ones ---
2929
struct ItaniumPMF
@@ -36,7 +36,7 @@ constexpr std::ptrdiff_t GetVirtualIndex() noexcept
3636

3737
std::ptrdiff_t adj;
3838
};
39-
constexpr union { decltype(METHOD) m; ItaniumPMF pmf; } u{ METHOD };
39+
constexpr union { F m; ItaniumPMF pmf; } u{ METHOD };
4040

4141
#if defined(_MSC_VER)
4242
auto *pAddr = reinterpret_cast<unsigned char *>(u.pmf.ptr);
@@ -129,6 +129,7 @@ constexpr std::ptrdiff_t GetVirtualIndex() noexcept
129129

130130
return DYNLIB_INVALID_VCALL;
131131
}
132+
template<auto METHOD> constexpr std::ptrdiff_t GetVirtualIndex() noexcept { return GetVirtualIndex<decltype(METHOD), METHOD>(); }
132133

133134
// Provides an interface to manipulate and invoke entries from a class's virtual table (vtable).
134135
class CVirtualTable

0 commit comments

Comments
 (0)