7#ifndef PXR_BASE_TF_FUNCTION_REF_H
8#define PXR_BASE_TF_FUNCTION_REF_H
16PXR_NAMESPACE_OPEN_SCOPE
81template <
class Ret,
class... Args>
88 template <
typename Fn>
89 using _IsFunctionRef = std::is_same<
90 std::remove_cv_t<std::remove_reference_t<Fn>>,
TfFunctionRef>;
94 template <class Fn, class = std::enable_if_t<!_IsFunctionRef<Fn>::value>>
96 : _fn(
static_cast<void const *
>(std::addressof(fn)))
97 , _invoke(_InvokeFn<Fn>) {}
110 std::enable_if_t<!_IsFunctionRef<Fn>::value,
112 operator=(Fn &fn)
noexcept {
120 std::swap(_fn, other._fn);
121 std::swap(_invoke, other._invoke);
125 inline Ret operator()(Args... args)
const {
126 return _invoke(_fn, std::forward<Args>(args)...);
131 static Ret _InvokeFn(
void const *fn, Args...args) {
132 using FnPtr =
typename std::add_pointer<
133 typename std::add_const<Fn>::type>::type;
134 return (*
static_cast<FnPtr
>(fn))(std::forward<Args>(args)...);
138 Ret (*_invoke)(
void const *, Args...);
149PXR_NAMESPACE_CLOSE_SCOPE
This class provides a non-owning reference to a type-erased callable object with a specified signatur...