diff --git a/include/continuable/detail/util.hpp b/include/continuable/detail/util.hpp index a6a48f7..c025b59 100644 --- a/include/continuable/detail/util.hpp +++ b/include/continuable/detail/util.hpp @@ -137,6 +137,31 @@ template is_invokable, std::forward(callable), std::forward(args)...); } +/// Invokes the given callable object with the given arguments +template +constexpr auto invoke(Callable&& callable, Args&&... args) noexcept( + noexcept(std::forward(callable)(std::forward(args)...))) + -> decltype(std::forward(callable)(std::forward(args)...)) { + + return std::forward(callable)(std::forward(args)...); +} +/// Invokes the given member function pointer by reference +template +constexpr auto invoke(Type T::*member, Self&& self, Args&&... args) noexcept( + noexcept((std::forward(self).*member)(std::forward(args)...))) + -> decltype((std::forward(self).* + member)(std::forward(args)...)) { + return (std::forward(self).*member)(std::forward(args)...); +} +/// Invokes the given member function pointer by pointer +template +constexpr auto invoke(Type T::*member, Self&& self, Args&&... args) noexcept( + noexcept((std::forward(self)->*member)(std::forward(args)...))) + -> decltype( + (std::forward(self)->*member)(std::forward(args)...)) { + return (std::forward(self)->*member)(std::forward(args)...); +} + // Class for making child classes non copyable struct non_copyable { constexpr non_copyable() = default; diff --git a/test/playground/comp.cpp b/test/playground/comp.cpp index 3b34c33..3516377 100644 --- a/test/playground/comp.cpp +++ b/test/playground/comp.cpp @@ -253,7 +253,34 @@ struct future_result { } // namespace detail } // namespace cti -using namespace cti::detail::remapping; +using namespace cti::detail; +using namespace remapping; + +template +struct promisify { + template + static auto from(Callable&& callable, Args&&... args) { + return cti::make_continuable([args = std::make_tuple( + std::forward( + callable), + std::forward(args)...)]( + auto&& promise) mutable { + + traits::unpack(std::move(args), [promise = + std::forward( + promise)]( + auto&&... args) mutable { + util::invoke( + std::forward(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>>::value> { @@ -280,7 +307,11 @@ int main(int, char**) { return; }, - &i, &r); + &i, &r);*/ + + auto t = [](auto&&...) {}; + + promisify::from(t, ""); return 0; }