11 #include "opentelemetry/version.h"
27 template <
class R,
class... Args>
30 void *callable_ =
nullptr;
31 R (*invoker_)(
void *, Args...) =
nullptr;
34 using FunctionPointer = decltype(std::addressof(std::declval<F &>()));
37 void BindTo(F &f) noexcept
39 callable_ =
static_cast<void *
>(std::addressof(f));
40 invoker_ = [](
void *callable, Args... args) -> R {
41 return (*
static_cast<FunctionPointer<F>
>(callable))(std::forward<Args>(args)...);
45 template <
class R_in,
class... Args_in>
46 void BindTo(R_in (*f)(Args_in...)) noexcept
48 using F = decltype(f);
51 return BindTo(
nullptr);
53 callable_ =
reinterpret_cast<void *
>(f);
54 invoker_ = [](
void *callable, Args... args) -> R {
55 return (F(callable))(std::forward<Args>(args)...);
59 void BindTo(std::nullptr_t) noexcept
68 typename std::enable_if<!std::is_same<function_ref, typename std::decay<F>::type>::value,
70 typename std::enable_if<
71 #if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402))
76 std::is_convertible<
typename std::result_of<F &(Args...)>::type, R>::value,
89 R operator()(Args... args)
const {
return invoker_(callable_, std::forward<Args>(args)...); }
91 explicit operator bool()
const {
return invoker_; }