mirror of
https://github.com/Naios/continuable.git
synced 2025-12-06 16:56:44 +08:00
Some ideas of a promisify helper
This commit is contained in:
parent
9be06f4bcc
commit
9c66b53f23
@ -137,6 +137,31 @@ template <typename T, typename... Args>
|
||||
is_invokable, std::forward<T>(callable), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/// Invokes the given callable object with the given arguments
|
||||
template <typename Callable, typename... Args>
|
||||
constexpr auto invoke(Callable&& callable, Args&&... args) noexcept(
|
||||
noexcept(std::forward<Callable>(callable)(std::forward<Args>(args)...)))
|
||||
-> decltype(std::forward<Callable>(callable)(std::forward<Args>(args)...)) {
|
||||
|
||||
return std::forward<Callable>(callable)(std::forward<Args>(args)...);
|
||||
}
|
||||
/// Invokes the given member function pointer by reference
|
||||
template <typename T, typename Type, typename Self, typename... Args>
|
||||
constexpr auto invoke(Type T::*member, Self&& self, Args&&... args) noexcept(
|
||||
noexcept((std::forward<Self>(self).*member)(std::forward<Args>(args)...)))
|
||||
-> decltype((std::forward<Self>(self).*
|
||||
member)(std::forward<Args>(args)...)) {
|
||||
return (std::forward<Self>(self).*member)(std::forward<Args>(args)...);
|
||||
}
|
||||
/// Invokes the given member function pointer by pointer
|
||||
template <typename T, typename Type, typename Self, typename... Args>
|
||||
constexpr auto invoke(Type T::*member, Self&& self, Args&&... args) noexcept(
|
||||
noexcept((std::forward<Self>(self)->*member)(std::forward<Args>(args)...)))
|
||||
-> decltype(
|
||||
(std::forward<Self>(self)->*member)(std::forward<Args>(args)...)) {
|
||||
return (std::forward<Self>(self)->*member)(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// Class for making child classes non copyable
|
||||
struct non_copyable {
|
||||
constexpr non_copyable() = default;
|
||||
|
||||
@ -253,7 +253,34 @@ struct future_result {
|
||||
} // namespace detail
|
||||
} // namespace cti
|
||||
|
||||
using namespace cti::detail::remapping;
|
||||
using namespace cti::detail;
|
||||
using namespace remapping;
|
||||
|
||||
template <typename... Result>
|
||||
struct promisify {
|
||||
template <typename Callable, typename... Args>
|
||||
static auto from(Callable&& callable, Args&&... args) {
|
||||
return cti::make_continuable<Result...>([args = std::make_tuple(
|
||||
std::forward<Callable>(
|
||||
callable),
|
||||
std::forward<Args>(args)...)](
|
||||
auto&& promise) mutable {
|
||||
|
||||
traits::unpack(std::move(args), [promise =
|
||||
std::forward<decltype(promise)>(
|
||||
promise)](
|
||||
auto&&... args) mutable {
|
||||
util::invoke(
|
||||
std::forward<decltype(args)>(args)..., [promise =
|
||||
std::move(promise)](
|
||||
auto&&... /*result*/){
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
int main(int, char**) {
|
||||
|
||||
@ -270,7 +297,7 @@ int main(int, char**) {
|
||||
auto r = create_result_pack(std::move(p));
|
||||
auto i = create_index_pack(std::move(p));
|
||||
|
||||
relocate_index_pack(
|
||||
/*relocate_index_pack(
|
||||
[](auto index, auto result)
|
||||
-> std::enable_if_t<is_indexed_continuable<
|
||||
std::remove_pointer_t<std::decay_t<decltype(index)>>>::value> {
|
||||
@ -280,7 +307,11 @@ int main(int, char**) {
|
||||
|
||||
return;
|
||||
},
|
||||
&i, &r);
|
||||
&i, &r);*/
|
||||
|
||||
auto t = [](auto&&...) {};
|
||||
|
||||
promisify<int>::from(t, "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user