29 #ifndef OTBR_COMMON_CALLBACK_HPP_
30 #define OTBR_COMMON_CALLBACK_HPP_
33 #include <type_traits>
54 template <
typename R,
typename... Args>
class OnceCallback<R(Args...)>
63 template <typename T, typename = typename std::enable_if<!std::is_same<OnceCallback, T>::value>::type>
65 : mFunc(std::forward<T>(func))
74 R operator()(Args...)
const &
76 static_assert(!
sizeof(*
this),
"OnceCallback::() can only be invoked on a non-const "
77 "rvalue, i.e. std::move(callback)().");
80 R operator()(Args... args) &&
86 return cb.mFunc(std::forward<Args>(args)...);
89 bool IsNull()
const {
return mFunc ==
nullptr; }
92 std::function<R(Args...)> mFunc;
97 #endif // OTBR_COMMON_CALLBACK_HPP_