-
Notifications
You must be signed in to change notification settings - Fork 0
/
signal_manip.hpp
89 lines (77 loc) · 2.52 KB
/
signal_manip.hpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef signal_manip_h
#define signal_manip_h
#include <utility>
#include <vector>
#include <future>
namespace signals {
template<typename s_t>
typename s_t::slot_id_t connect(s_t const& sig, typename s_t::slot_t&& slot)
{
return const_cast<s_t&>(sig).connect(std::forward<typename s_t::slot_t&&>(slot));
}
template<typename s_t>
typename s_t::slot_t disconect(s_t const& sig, typename s_t::slot_id_t const& id)
{
return const_cast<s_t&>(sig).disconnect(id);
}
template<typename s_t, typename... args_t>
auto emit(s_t const& sig, args_t&&... args) -> decltype(std::declval<s_t>().emit(std::declval<args_t>()...))
{
return const_cast<s_t&>(sig).emit(std::forward<args_t&&>(args)...);
}
template<typename s_t, typename s_id_t,typename... args_t>
auto emit(s_t const& sig, s_id_t const& target, args_t&&...args)->decltype(std::declval<s_t>().emit(std::declval<s_id_t>(),
std::declval<args_t>()...))
{
return const_cast<s_t&>(sig).emit(target,std::forward<args_t&&>(args)...);
}
template<typename T,typename sid_t>
T result(sid_t&& sid,std::vector<std::future<T>>&& v){
return v[sid].get();
}
template<typename T,typename sid_t>
T result(sid_t& sid,std::vector<std::future<T>>& v){
return v[sid].get();
}
template<typename T,typename sid_t>
T result(sid_t&& sid,std::vector<T>&& v){
return v[sid];
}
template<typename T,typename sid_t>
T result(sid_t& sid,std::vector<T>& v){
return v[sid];
}
template<typename T>
std::vector<T> result(std::vector<std::future<T>>&& v){
std::vector<T> out(v.size());
for(std::size_t i=0;i<v.size();++i){
out[i]=v[i].get();
}
return out;
}
template<typename T>
std::vector<T> result(std::vector<std::future<T>>& v){
std::vector<T> out(v.size());
for(std::size_t i=0;i<v.size();++i){
out[i]=v[i].get();
}
return out;
}
template<typename T>
inline std::vector<T>& result(std::vector<T>&& v){
return v;
}
template<typename T>
inline std::vector<T>& result(std::vector<T>& v){
return v;
}
template<typename T>
inline T& result(std::future<T>&& v){
return v.get();
}
template<typename T>
inline T result(std::future<T>& v){
return v.get();
}
}
#endif /* signal_manip_h */