aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2016-02-16 23:30:16 +0100
committerAdrian Kummerlaender2016-02-16 23:30:16 +0100
commitf4353423207c451244ce9118b54ef3dcb28c7f89 (patch)
treeaa033e600ffdd8360d137faf44abd652a30676df
parent6fd2e1dea2625a975347ada0a23fb172aeeb28c7 (diff)
downloadchange-f4353423207c451244ce9118b54ef3dcb28c7f89.tar
change-f4353423207c451244ce9118b54ef3dcb28c7f89.tar.gz
change-f4353423207c451244ce9118b54ef3dcb28c7f89.tar.bz2
change-f4353423207c451244ce9118b54ef3dcb28c7f89.tar.lz
change-f4353423207c451244ce9118b54ef3dcb28c7f89.tar.xz
change-f4353423207c451244ce9118b54ef3dcb28c7f89.tar.zst
change-f4353423207c451244ce9118b54ef3dcb28c7f89.zip
Replace `std::function` with raw function pointer
-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;
}
}