24 #ifndef LELY_IO2_USER_TIMER_HPP_
25 #define LELY_IO2_USER_TIMER_HPP_
43 if (!timer) util::throw_errc(
"UserTimer");
49 other.timer =
nullptr;
58 swap(timer, other.timer);
67 template <class T, class U = typename ::std::decay<T>::type>
69 typename ::std::enable_if<compat::is_invocable<U, const timespec*>::value,
72 ::std::reference_wrapper<T> obj) {
73 return UserTimer(ctx, exec,
74 [](
const timespec* tp,
void* arg) noexcept {
75 auto* obj =
static_cast<T*
>(arg);
78 static_cast<void*
>(
const_cast<U*
>(&obj.get())));
81 template <class T, class U = typename ::std::decay<T>::type>
82 inline typename ::std::enable_if<
83 compat::is_invocable<U, const UserTimer::time_point&>::value,
86 ::std::reference_wrapper<T> obj) {
87 return UserTimer(ctx, exec,
88 [](
const timespec* tp,
void* arg) noexcept {
89 auto* obj =
static_cast<T*
>(arg);
90 (*obj)(UserTimer::time_point{util::from_timespec(*tp)});
92 static_cast<void*
>(
const_cast<U*
>(&obj.get())));
95 template <
class C,
void (C::*M)(const timespec*)>
98 return UserTimer(ctx, exec,
99 [](
const timespec* tp,
void* arg) noexcept {
100 auto obj =
static_cast<C*
>(arg);
103 static_cast<void*
>(obj));
106 template <
class C,
void (C::*M)(const UserTimer::time_po
int&)>
109 return UserTimer(ctx, exec,
110 [](
const timespec* tp,
void* arg) noexcept {
111 auto obj =
static_cast<C*
>(arg);
112 (obj->*M)(UserTimer::time_point{util::from_timespec(*tp)});
114 static_cast<void*
>(obj));
120 #endif // !LELY_IO2_USER_TIMER_HPP_