diff --git a/include/continuable/continuable-base.hpp b/include/continuable/continuable-base.hpp index a2b14ca..2321df9 100644 --- a/include/continuable/continuable-base.hpp +++ b/include/continuable/continuable-base.hpp @@ -578,13 +578,23 @@ public: return materializer::apply(std::move(*this)); } +#ifdef DOXYGEN /// Returns true if the continuable_base will resolve its promise /// immediately on request. /// /// \since 4.0.0 - bool is_ready() const noexcept { - return false; - } + bool is_ready() const noexcept; +#endif + +#ifdef DOXYGEN + /// Returns the result of this continuable immediatly. + /// + /// \attention requires that this continuable resolves immediatly on + /// request which means that is_ready() holds. + /// + /// \since 4.0.0 + unspecified request() &&; +#endif /// Predicate to check whether the cti::continuable_base is frozen or not. /// @@ -732,6 +742,18 @@ private: } }; +/*template +struct continuable_trait +#ifdef DOXYGEN +{ + /// Deduces to a true_type if the continuable_base is a concrete type + /// which means all lazy expression templates were materialized and + /// the continuable can be queried for a direct result through is_ready. + using is_concrete = std::true_type; +} +#endif +;*/ + /// Creates a continuable_base from a promise/callback taking function. /// /// \tparam Args The types (signature hint) the given promise is resolved with. diff --git a/include/continuable/continuable-coroutine.hpp b/include/continuable/continuable-coroutine.hpp index d08d709..364ad03 100644 --- a/include/continuable/continuable-coroutine.hpp +++ b/include/continuable/continuable-coroutine.hpp @@ -52,7 +52,7 @@ namespace experimental { template struct coroutine_traits< cti::continuable_base>, + cti::detail::traits::identity>, FunctionArgs...> { using promise_type = diff --git a/include/continuable/continuable-promise-base.hpp b/include/continuable/continuable-promise-base.hpp index 0d5431a..8765dd1 100644 --- a/include/continuable/continuable-promise-base.hpp +++ b/include/continuable/continuable-promise-base.hpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include @@ -62,7 +62,7 @@ class promise_base /// \cond false ; template -class promise_base> +class promise_base> : detail::util::non_copyable /// \endcond { // clang-format on @@ -78,7 +78,7 @@ public: } /// \cond false /// Constructor for constructing an empty promise - explicit promise_base(detail::types::promise_no_init_tag) { + explicit promise_base(detail::types::promise_no_init_arg_t) { } /// \endcond diff --git a/include/continuable/continuable-trait.hpp b/include/continuable/continuable-trait.hpp index b30e5dd..122d40e 100644 --- a/include/continuable/continuable-trait.hpp +++ b/include/continuable/continuable-trait.hpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include namespace cti { @@ -67,12 +67,12 @@ class continuable_trait { public: /// The promise type which is used to resolve continuations using promise = - promise_base>; + promise_base>; /// The continuable type for the given parameters. using continuable = continuable_base, - detail::hints::signature_hint_tag>; + detail::traits::identity>; }; /// \} } // namespace cti diff --git a/include/continuable/detail/connection/connection-aggregated.hpp b/include/continuable/detail/connection/connection-aggregated.hpp index 96838cc..ad06059 100644 --- a/include/continuable/detail/connection/connection-aggregated.hpp +++ b/include/continuable/detail/connection/connection-aggregated.hpp @@ -75,17 +75,17 @@ T&& unpack_lazy(container::flat_variant&& value) { template class continuable_box; template -class continuable_box>> { +class continuable_box>> { - continuable_base> continuable_; + continuable_base> continuable_; public: explicit continuable_box( - continuable_base>&& continuable) + continuable_base>&& continuable) : continuable_(std::move(continuable)) { } - continuable_base>&& fetch() { + continuable_base>&& fetch() { return std::move(continuable_); } @@ -98,18 +98,18 @@ public: }; template class continuable_box< - continuable_base>> { + continuable_base>> { - continuable_base> continuable_; + continuable_base> continuable_; lazy_value_t first_; public: explicit continuable_box( - continuable_base>&& continuable) + continuable_base>&& continuable) : continuable_(std::move(continuable)) { } - continuable_base>&& fetch() { + continuable_base>&& fetch() { return std::move(continuable_); } @@ -123,21 +123,21 @@ public: }; template class continuable_box< - continuable_base>> { + continuable_base>> { - continuable_base> + continuable_base> continuable_; lazy_value_t> args_; public: explicit continuable_box( continuable_base>&& + traits::identity>&& continuable) : continuable_(std::move(continuable)) { } - continuable_base>&& + continuable_base>&& fetch() { return std::move(continuable_); } @@ -215,7 +215,7 @@ constexpr auto finalize_impl(traits::identity>, struct hint_mapper { template - constexpr auto operator()(T...) -> hints::signature_hint_tag { + constexpr auto operator()(T...) -> traits::identity { return {}; } }; diff --git a/include/continuable/detail/connection/connection-all.hpp b/include/continuable/detail/connection/connection-all.hpp index 3d10720..27e084b 100644 --- a/include/continuable/detail/connection/connection-all.hpp +++ b/include/continuable/detail/connection/connection-all.hpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/continuable/detail/connection/connection-any.hpp b/include/continuable/detail/connection/connection-any.hpp index 25be4ac..ec601b8 100644 --- a/include/continuable/detail/connection/connection-any.hpp +++ b/include/continuable/detail/connection/connection-any.hpp @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include #include @@ -95,7 +95,7 @@ struct result_deducer { } template static auto deduce_one(std::true_type, traits::identity id) { - return hints::hint_of(id); + return base::annotation_of(id); } template static auto deduce(traversal::container_category_tag, diff --git a/include/continuable/detail/core/hints.hpp b/include/continuable/detail/core/annotation.hpp similarity index 81% rename from include/continuable/detail/core/hints.hpp rename to include/continuable/detail/core/annotation.hpp index 6322579..99420ce 100644 --- a/include/continuable/detail/core/hints.hpp +++ b/include/continuable/detail/core/annotation.hpp @@ -28,8 +28,8 @@ SOFTWARE. **/ -#ifndef CONTINUABLE_DETAIL_HINTS_HPP_INCLUDED -#define CONTINUABLE_DETAIL_HINTS_HPP_INCLUDED +#ifndef CONTINUABLE_DETAIL_ANNOTATION_HPP_INCLUDED +#define CONTINUABLE_DETAIL_ANNOTATION_HPP_INCLUDED #include #include @@ -37,18 +37,18 @@ namespace cti { namespace detail { -namespace hints { -/// Represents a present signature hint +template +struct annotation_trait; + +/// Specialization for a present signature hint template -using signature_hint_tag = traits::identity; - -/// Returns the signature hint of the given continuable -template -constexpr signature_hint_tag -hint_of(traits::identity>>) { - return {}; -} +struct annotation_trait> { + using is_concrete_hint = std::true_type; + using hint_t = traits::identity; + using is_materialized = std::true_type; +}; +namespace hints { /// Extracts the signature we pass to the internal continuable /// from an argument pack as specified by make_continuable. /// @@ -67,4 +67,4 @@ constexpr auto extract(traits::identity /*hint*/) { } // namespace detail } // namespace cti -#endif // CONTINUABLE_DETAIL_HINTS_HPP_INCLUDED +#endif // CONTINUABLE_DETAIL_ANNOTATION_HPP_INCLUDED diff --git a/include/continuable/detail/core/base.hpp b/include/continuable/detail/core/base.hpp index 83a1750..56b1726 100644 --- a/include/continuable/detail/core/base.hpp +++ b/include/continuable/detail/core/base.hpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #include #include @@ -69,6 +69,39 @@ struct is_continuable : std::false_type {}; template struct is_continuable> : std::true_type {}; +/*template +struct ready_continuable { + std::tuple values_; + + template + void operator()(Callback&& callback) && { + traits::unpack(std::forward(callback), std::move(values_)); + } + + bool operator()(is_ready_arg_t) const noexcept { + return true; + } + + std::tuple operator()(get_arg_t) && { + return std::move(values_); + } +};*/ + +/*template +struct proxy_continuable : Continuation { + using Continuation::Continuation; + + using Continuation::operator(); + + bool operator()(is_ready_arg_t) const noexcept { + return false; + } + + std::tuple operator()(get_arg_t) && { + util::unreachable(); + } +};*/ + struct attorney { /// Creates a continuable_base from the given continuation, annotation /// and ownership. @@ -78,7 +111,7 @@ struct attorney { static auto create_from(T&& continuation, A annotation, util::ownership ownership) { (void)annotation; - return Continuable(std::forward(continuation), ownership); + return Continuable({std::forward(continuation)}, ownership); } /// Returns the ownership of the given continuable_base @@ -93,6 +126,14 @@ struct attorney { } }; +/// Returns the signature hint of the given continuable +template +constexpr traits::identity +annotation_of(traits::identity>>) { + return {}; +} + /// Invokes a continuation object in a reference correct way template void invoke_continuation(continuable_base&& continuation, @@ -180,8 +221,8 @@ void invoke_void_no_except(traits::identity, T&& callable) noexcept { } template -constexpr auto make_invoker(T&& invoke, hints::signature_hint_tag) { - return invoker, hints::signature_hint_tag>( +constexpr auto make_invoker(T&& invoke, traits::identity) { + return invoker, traits::identity>( std::forward(invoke)); } @@ -193,7 +234,7 @@ invoker_of(traits::identity>) { using Type = decltype(std::declval>().finish()); - auto constexpr const hint = hints::hint_of(traits::identify{}); + auto constexpr const hint = base::annotation_of(traits::identify{}); return make_invoker( [](auto&& callback, auto&& next_callback, auto&&... args) { @@ -405,7 +446,7 @@ template struct result_handler_base; template struct result_handler_base> { + traits::identity> { void operator()(Args... args) && { // Forward the arguments to the next callback std::move(static_cast(this)->next_callback_)(std::move(args)...); @@ -413,7 +454,7 @@ struct result_handler_base struct result_handler_base> { + traits::identity> { /// The operator which is called when the result was provided void operator()(Args... args) && { // In order to retrieve the correct decorator we must know what the @@ -475,17 +516,17 @@ struct callback_base; template -struct callback_base, HandleResults, - HandleErrors, Callback, Executor, NextCallback> +struct callback_base, HandleResults, HandleErrors, + Callback, Executor, NextCallback> : proto::result_handler_base< HandleResults, - callback_base, HandleResults, - HandleErrors, Callback, Executor, NextCallback>, - hints::signature_hint_tag>, + callback_base, HandleResults, HandleErrors, + Callback, Executor, NextCallback>, + traits::identity>, proto::error_handler_base< HandleErrors, - callback_base, HandleResults, - HandleErrors, Callback, Executor, NextCallback>>, + callback_base, HandleResults, HandleErrors, + Callback, Executor, NextCallback>>, util::non_copyable { Callback callback_; @@ -501,16 +542,15 @@ struct callback_base, HandleResults, /// Pull the result handling operator() in using proto::result_handler_base< HandleResults, - callback_base, HandleResults, - HandleErrors, Callback, Executor, NextCallback>, - hints::signature_hint_tag>::operator(); + callback_base, HandleResults, HandleErrors, + Callback, Executor, NextCallback>, + traits::identity>::operator(); /// Pull the error handling operator() in using proto::error_handler_base< HandleErrors, - callback_base, HandleResults, - HandleErrors, Callback, Executor, NextCallback>>:: - operator(); + callback_base, HandleResults, HandleErrors, + Callback, Executor, NextCallback>>::operator(); /// Resolves the continuation with the given values void set_value(Args... args) { @@ -581,7 +621,7 @@ template constexpr auto next_hint_of(std::integral_constant, traits::identity /*callback*/, - hints::signature_hint_tag /*current*/) { + traits::identity /*current*/) { // Partial Invoke the given callback using Result = decltype( decoration::invoke_callback(std::declval(), std::declval()...)); @@ -594,7 +634,7 @@ template constexpr auto next_hint_of(std::integral_constant, traits::identity /*callback*/, - hints::signature_hint_tag current) { + traits::identity current) { return current; } @@ -635,7 +675,7 @@ auto chain_continuation(Continuation&& continuation, Callback&& callback, static_assert(is_continuable>{}, "Expected a continuation!"); - using Hint = decltype(hints::hint_of(traits::identify())); + using Hint = decltype(base::annotation_of(traits::identify())); constexpr auto next_hint = next_hint_of(std::integral_constant{}, traits::identify{}, Hint{}); diff --git a/include/continuable/detail/core/types.hpp b/include/continuable/detail/core/types.hpp index 5cff5f6..c94cd34 100644 --- a/include/continuable/detail/core/types.hpp +++ b/include/continuable/detail/core/types.hpp @@ -75,7 +75,7 @@ public: }; /// Tag for constructing an empty promise_base . -struct promise_no_init_tag {}; +struct promise_no_init_arg_t {}; } // namespace types } // namespace detail } // namespace cti diff --git a/include/continuable/detail/other/coroutines.hpp b/include/continuable/detail/other/coroutines.hpp index 2e22ad5..ba200c3 100644 --- a/include/continuable/detail/other/coroutines.hpp +++ b/include/continuable/detail/other/coroutines.hpp @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include #include #include @@ -65,7 +65,7 @@ struct result_from_identity> { /// for waiting on a continuable in a stackless coroutine. template class awaitable { - using hint_t = decltype(hints::hint_of(traits::identify{})); + using hint_t = decltype(base::annotation_of(traits::identify{})); using result_t = typename result_from_identity::result_t; /// The continuable which is invoked upon suspension @@ -186,7 +186,7 @@ struct promise_type : promise_resolver_base> { coroutine_handle<> handle_; Promise promise_; - explicit promise_type() : promise_(types::promise_no_init_tag{}) { + explicit promise_type() : promise_(types::promise_no_init_arg_t{}) { } auto get_return_object() { diff --git a/include/continuable/detail/other/transforms.hpp b/include/continuable/detail/other/transforms.hpp index 3ca3c12..7f56546 100644 --- a/include/continuable/detail/other/transforms.hpp +++ b/include/continuable/detail/other/transforms.hpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include @@ -77,7 +77,7 @@ template class promise_callback; template -class promise_callback> +class promise_callback> : public future_trait { typename future_trait::promise_t promise_; @@ -119,7 +119,7 @@ template auto as_future(continuable_base&& continuable) { // Create the promise which is able to supply the current arguments constexpr auto const hint = - hints::hint_of(traits::identify{}); + base::annotation_of(traits::identify{}); promise_callback> callback; (void)hint; diff --git a/include/continuable/detail/utility/result-trait.hpp b/include/continuable/detail/utility/result-trait.hpp index 66c0647..ebcf0b7 100644 --- a/include/continuable/detail/utility/result-trait.hpp +++ b/include/continuable/detail/utility/result-trait.hpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include