-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallback_cpp11.h
More file actions
30 lines (25 loc) · 1.1 KB
/
callback_cpp11.h
File metadata and controls
30 lines (25 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once
#ifndef _OBJC_CALLBACK_H_
#define _OBJC_CALLBACK_H_
template<typename Signature> class objc_callback;
template<typename R, typename... Ts>
class objc_callback<R(Ts...)>
{
public:
typedef R (*func)(id, SEL, Ts...);
objc_callback(SEL sel, id obj)
: sel_(sel)
, obj_(obj)
, fun_((func)[obj methodForSelector:sel])
{
}
inline R operator ()(Ts... vs)
{
return fun_(obj_, sel_, vs...);
}
private:
SEL sel_;
id obj_;
func fun_;
};
#endif // _OBJC_CALLBACK_H_