20 #include <type_traits>
87 template<
typename Ret,
typename... Params>
class FunctionRef<Ret(Params...)> {
105 template<
typename Callable>
static Ret callback_fn(
intptr_t callable, Params...
params)
107 return (*
reinterpret_cast<Callable *
>(callable))(std::forward<Params>(
params)...);
123 template<
typename Callable,
124 std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Callable>>,
127 : callback_(callback_fn<typename
std::remove_reference_t<Callable>>),
128 callable_(reinterpret_cast<
intptr_t>(&callable))
140 return callback_(callable_, std::forward<Params>(
params)...);
152 if constexpr (std::is_void_v<Ret>) {
153 if (callback_ ==
nullptr) {
156 callback_(callable_, std::forward<Params>(
params)...);
159 if (callback_ ==
nullptr) {
162 return callback_(callable_, std::forward<Params>(
params)...);
170 operator bool()
const
174 return callback_ !=
nullptr;
FunctionRef(Callable &&callable)
std::conditional_t< std::is_void_v< Ret >, void, std::optional< Ret > > OptionalReturnValue
OptionalReturnValue call_safe(Params... params) const
Ret operator()(Params... params) const