7 #ifndef __MERCURY_COROUTINE_ENGINE_FUNCTION_UTILITY__
8 #define __MERCURY_COROUTINE_ENGINE_FUNCTION_UTILITY__
11 #include <type_traits>
18 using unqualified =
typename std::decay<T>::type;
21 #if __cplusplus >= 201703L
22 template <
typename F,
typename... Ts>
23 using function_return_type =
typename std::invoke_result<unqualified<F>,Ts...>::type;
25 template <
typename F,
typename... Ts>
26 using function_return_type =
typename std::result_of<unqualified<F>(Ts...)>::type;
42 template <
typename F,
typename... A>
43 using convert_void_return =
typename convert_void_<function_return_type<F,A...>>::type;
45 template<
typename T,
typename _ =
void>
48 template<
typename... Ts>
51 template<
bool B,
class T,
class F >
52 using conditional_t =
typename std::conditional<B,T,F>::type;
60 typename T::value_type,
62 decltype(std::declval<T>().begin()),
63 decltype(std::declval<T>().end())
67 > :
public std::true_type {};
72 using thunk = std::function<void()>;
77 template <
typename F,
typename... A>
78 std::function<detail::function_return_type<F,A...>()>
81 return std::bind(std::forward<F>(func), std::forward<A>(args)...);
85 inline thunk wrap_return(std::true_type,
thunk th)
91 template <
typename Callable>
92 thunk wrap_return(std::false_type, Callable&& cb)
99 inline void operator()(){ inner(); }
103 return wrapper{ std::forward<Callable>(cb) };
109 template <
typename Callable>
110 thunk make_thunk(Callable&& cb)
113 using isv =
typename std::is_void<detail::function_return_type<Callable>>;
114 return detail::wrap_return(
115 std::integral_constant<bool,isv::value>(),
116 std::forward<Callable>(cb));
124 template <
typename Callable,
typename A,
typename... As>
125 thunk make_thunk(Callable&& cb, A&& a, As&&... as)
130 std::forward<Callable>(cb),
132 std::forward<As>(as)...));
std::function< void()> thunk
thunk type definition. Also known as a nullary function
Definition: function_utility.hpp:72
std::function< detail::function_return_type< F, A... >)> wrap_args(F &&func, A &&... args)
std::bind arguments to an std::function
Definition: function_utility.hpp:79
Definition: function_utility.hpp:32
Definition: function_utility.hpp:49
Definition: function_utility.hpp:46