Skip to content

Commit 6d64ba2

Browse files
committed
VTMHook: add void return type support
1 parent b404b87 commit 6d64ba2

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

include/dynlibutils/vthook.hpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <cstdint>
2828
#include <functional>
2929
#include <map>
30+
#include <type_traits>
3031

3132
namespace DynLibUtils {
3233

@@ -223,10 +224,7 @@ class CVTMHookBase
223224
{
224225
auto found = Find(CVirtualTable(pThis));
225226

226-
if (found.first == found.second)
227-
{
228-
return {};
229-
}
227+
assert(found.first != found.second);
230228

231229
return found.first->second.Call(pThis, args...);
232230
}
@@ -240,10 +238,7 @@ class CVTMHookBase
240238

241239
auto found = Find(CVirtualTable(pThis));
242240

243-
if (found.first == found.second)
244-
{
245-
return results;
246-
}
241+
assert(found.first != found.second);
247242

248243
// results.reserve(vhooks.size());
249244

@@ -389,14 +384,26 @@ class CVTFMHook : public CVTMHook<R, T, Args...>
389384

390385
auto &callbacks = found->second;
391386

392-
R result {};
393-
394-
for (auto it : callbacks)
387+
if constexpr (std::is_void_v<R>)
395388
{
396-
result = it(pClass, args...);
389+
for (const auto &callback : callbacks)
390+
{
391+
callback(pClass, args...);
392+
}
393+
394+
return;
397395
}
396+
else
397+
{
398+
R result {};
398399

399-
return result;
400+
for (const auto &callback : callbacks)
401+
{
402+
result = callback(pClass, args...);
403+
}
404+
405+
return result;
406+
}
400407
}
401408
);
402409
}

0 commit comments

Comments
 (0)