aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/actual_function.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/actual_function.h b/src/actual_function.h
index 8229ccf..ff69a13 100644
--- a/src/actual_function.h
+++ b/src/actual_function.h
@@ -14,15 +14,17 @@
namespace {
template <class Result, typename... Arguments>
- std::function<Result(Arguments...)> get_actual_function(
- const std::string& symbol_name) {
+ using function_ptr = Result(*)(Arguments...);
- Result (*real_function)(Arguments...) = nullptr;
- const void* symbol_address = dlsym(RTLD_NEXT, symbol_name.c_str());
+ template <class Result, typename... Arguments>
+ function_ptr<Result, Arguments...> get_actual_function(
+ const std::string& symbol_name) {
+ const void* symbol_address{ dlsym(RTLD_NEXT, symbol_name.c_str()) };
- std::memcpy(&real_function, &symbol_address, sizeof(symbol_address));
+ function_ptr<Result, Arguments...> actual_function{};
+ std::memcpy(&actual_function, &symbol_address, sizeof(symbol_address));
- return std::function<Result(Arguments...)>(real_function);
+ return actual_function;
}
}