#
Scopes of type simple_counting_scope and counting_scope maintain counts of associations.
Let:
During its lifetime scope goes through different states which govern what operations are allowed and the result of these operations:
2
#
Recommended practice: For simple_counting_scope and counting_scope, implementations should store the state and the count of associations in a single member of type size_t.
Subclause [exec.counting.scopes] makes use of the following exposition-only entities:
struct scope-join-t {}; / exposition only enum scope-state-type { / exposition only unused, / exposition only open, / exposition only closed, / exposition only open-and-joining, / exposition only closed-and-joining, / exposition only unused-and-closed, / exposition only joined, / exposition only }; template<class Scope> struct association-t; / exposition only
The exposition-only class template impls-for ([exec.snd.expos]) is specialized for scope-join-t as follows:
namespace std::execution { template<> struct impls-for<scope-join-t> : default-impls { template<class Scope, class Rcvr> struct state { / exposition only struct rcvr-t { / exposition only using receiver_concept = receiver_t; Rcvr& rcvr; / exposition only void set_value() && noexcept { execution::set_value(std::move(rcvr)); } template<class E> void set_error(E&& e) && noexcept { execution::set_error(std::move(rcvr), std::forward<E>(e)); } void set_stopped() && noexcept { execution::set_stopped(std::move(rcvr)); } decltype(auto) get_env() const noexcept { return execution::get_env(rcvr); } }; using sched-sender = / exposition only decltype(schedule(get_scheduler(get_env(declval<Rcvr&>(); using op-t = / exposition only connect_result_t<sched-sender, rcvr-t>; Scope* scope; / exposition only Rcvr& receiver; / exposition only op-t op; / exposition only state(Scope* scope, Rcvr& rcvr) / exposition only noexcept(nothrow-callable<connect_t, sched-sender, rcvr-t>) : scope(scope), receiver(rcvr), op(connect(schedule(get_scheduler(get_env(rcvr)), rcvr-t(rcvr)) {} void complete() noexcept { / exposition only start(op); } void complete-inline() noexcept { / exposition only set_value(std::move(receiver)); } }; static constexpr auto get-state = / exposition only []<class Rcvr>(auto& sender, Rcvr& receiver) noexcept(is_nothrow_constructible_v<state<Rcvr>, data-type<decltype(sender)>, Rcvr&>) { auto[_, self] = sender; return state(self, receiver); }; static constexpr auto start = / exposition only [](auto& s, auto&) noexcept { if (s.scope->start-join-sender(s)) s.complete-inline(); }; }; }
association-t is a class template, specializations of which model scope_association and contain an exposition-only member scope of type Scope*.
For a class type Scope and an object assoc of type association-t<Scope>:
  • assoc.scope points to its associated scope,
  • assoc is engaged when assoc.scope != nullptr is true,
  • if assoc is engaged, then assoc.try_associate() is equivalent to assoc.scope->try-associate(), and
  • the association owned by assoc is released by invoking assoc.scope->disassociate().

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant