-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallablewrapper.cpp
More file actions
47 lines (39 loc) · 1.56 KB
/
callablewrapper.cpp
File metadata and controls
47 lines (39 loc) · 1.56 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef CALLABLEWRAPPER_CALLABLEWRAPPER_CPP
#define CALLABLEWRAPPER_CALLABLEWRAPPER_CPP
#include "callablewrapper.h"
#include <utility>
namespace CallableWrapper {
template<typename C, typename RT, typename... Args>
CallableObjWrapper<C,RT,Args...>::CallableObjWrapper(C callable):
callable_(callable)
{
}
template<typename C, typename RT, typename... Args>
RT CallableObjWrapper<C,RT,Args...>::operator()(Args... args){
return callable_(std::forward<Args>(args)...);
}
template<typename C, typename RT, typename... Args>
CallablePtrWrapper<C,RT,Args...>::CallablePtrWrapper(C callable)
{
callable_ = callable;
}
template<typename C, typename RT, typename... Args>
RT CallablePtrWrapper<C,RT,Args...>::operator()(Args... args){
return (*callable_)(std::forward<Args>(args)...);
}
template<typename RT, typename... Args>
template<typename Callable>
CallableWrapper<RT, Args...>* CallableWrapperFactory<RT,Args...>::create(Callable callable){
if constexpr (std::is_pointer_v<Callable>){
return new CallablePtrWrapper<Callable, RT,Args...>(callable);
}
else if (std::is_copy_constructible_v<Callable>) {
return new CallableObjWrapper<Callable, RT,Args...>(callable);
}
else if (std::is_move_constructible_v<Callable>) {
return new CallableObjWrapper<Callable, RT,Args...>(std::move(callable));
}
return new CallableObjWrapper<Callable, RT,Args...>(callable);
}
} // namespace CallableWrapper
#endif