14 template <
typename Sig>
24 template <
typename R,
typename...
Args>
36 handle = dlopen(lib, RTLD_LAZY);
38 throw std::runtime_error(dlerror());
39 void *sym = dlsym(
handle, name);
42 throw std::runtime_error(dlerror());
44 fn =
reinterpret_cast<Fn>(sym);
53 handle = dlopen(
nullptr, RTLD_LAZY);
55 throw std::runtime_error(dlerror());
56 void *sym = dlsym(
handle, name);
59 throw std::runtime_error(dlerror());
61 fn =
reinterpret_cast<Fn>(sym);
73 other.handle =
nullptr;
82 other.handle =
nullptr;
91 throw std::runtime_error(
"Null function pointer");
92 return fn(std::forward<Args>(args)...);
Function(char const *name)
Load a function from the main program's symbol table.
Function(Function &&other) noexcept
Function & operator=(Function &&other) noexcept
Function & operator=(const Function &)=delete
Function(const Function &)=delete
void * handle
dlopen library handle
R operator()(Args... args) const
Invoke the loaded function.
Function(char const *lib, char const *name)
Load a function from a named shared library.
Fn fn
resolved function pointer