[exec.scope.counting]

# 33 Execution control library [[exec]](./#exec)

## 33.14 Execution scope utilities [[exec.scope]](exec.scope#counting)

### 33.14.2 Counting Scopes [[exec.counting.scopes]](exec.counting.scopes#exec.scope.counting)

#### 33.14.2.3 Counting Scope [exec.scope.counting]

[ð](#lib:execution::counting_scope)

namespace std::execution {class counting_scope {public:struct token {template<[sender](exec.snd.concepts#concept:sender "33.9.3 Sender concepts [exec.snd.concepts]") Sender>[sender](exec.snd.concepts#concept:sender "33.9.3 Sender concepts [exec.snd.concepts]") auto wrap(Sender&& snd) const noexcept(*see below*); bool try_associate() const noexcept; void disassociate() const noexcept; private: counting_scope* *scope*; // *exposition only*}; static constexpr size_t max_associations = *implementation-defined*;

 counting_scope() noexcept;
 counting_scope(counting_scope&&) = delete; ~counting_scope();

 token get_token() noexcept; void close() noexcept; [sender](exec.snd.concepts#concept:sender "33.9.3 Sender concepts [exec.snd.concepts]") auto join() noexcept; void request_stop() noexcept; private: size_t *count*; // *exposition only**scope-state-type* *state*; // *exposition only* inplace_stop_source *s_source*; // *exposition only*bool *try-associate*() noexcept; // *exposition only*void *disassociate*() noexcept; // *exposition only*template<class State>bool *start-join-sender*(State& state) noexcept; // *exposition only*};}

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L8230)

counting_scope differs from simple_counting_scope by
adding support for cancellation[.](#1.sentence-1)

Unless specified below, the semantics of members of counting_scope are the same as the corresponding members of simple_counting_scope[.](#1.sentence-2)

[ð](#lib:get_token,execution::counting_scope)

`token get_token() noexcept;
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L8242)

*Returns*: An object t of type counting_scope​::​token such thatt.*scope* == this is true[.](#2.sentence-1)

[ð](#lib:request_stop,execution::counting_scope)

`void request_stop() noexcept;
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L8254)

*Effects*: Equivalent to *s_source*.request_stop()[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L8258)

*Remarks*: Calls to request_stop do not introduce data races[.](#4.sentence-1)

[ð](#lib:wrap,execution::counting_scope::token)

`template<[sender](exec.snd.concepts#concept:sender "33.9.3 Sender concepts [exec.snd.concepts]") Sender>
  [sender](exec.snd.concepts#concept:sender "33.9.3 Sender concepts [exec.snd.concepts]") auto counting_scope::token::wrap(Sender&& snd) const
    noexcept(is_nothrow_constructible_v<remove_cvref_t<Sender>, Sender>);
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/exec.tex#L8271)

*Effects*: Equivalent to:return *stop-when*(std::forward<Sender>(snd), *scope*->*s_source*.get_token());
