forked from citizenfx/fivem
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSharedFunction.h
More file actions
29 lines (26 loc) · 746 Bytes
/
SharedFunction.h
File metadata and controls
29 lines (26 loc) · 746 Bytes
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
#pragma once
// blindly copypasted from StackOverflow (to allow std::function to store the funcref types with their move semantics)
template<class F>
struct shared_function
{
std::shared_ptr<F> f;
shared_function() = default;
shared_function(F&& f_)
: f(std::make_shared<F>(std::move(f_)))
{
}
shared_function(shared_function const&) = default;
shared_function(shared_function&&) = default;
shared_function& operator=(shared_function const&) = default;
shared_function& operator=(shared_function&&) = default;
template<class... As>
auto operator()(As&&... as) const
{
return (*f)(std::forward<As>(as)...);
}
};
template<class F>
shared_function<std::decay_t<F>> make_shared_function(F&& f)
{
return { std::forward<F>(f) };
}