Skip to content

Commit ab7abd8

Browse files
authored
add overview for some of the queries (#146)
* add overview for some of the queries * fix trailing space
1 parent d29940d commit ab7abd8

File tree

1 file changed

+100
-5
lines changed

1 file changed

+100
-5
lines changed

docs/overview.md

Lines changed: 100 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ struct example_state
336336
</details>
337337
<details>
338338
<summary><code>unstoppable_token&lt;_Token_&gt;</code></summary>
339-
The concept <code>unstoppable_token&lt;Token&gt;</code> is modeled by a <code>_Token_</code> if <code>stoppable_token&lt;_Token_&gt;</code> is true and it can statically be determined that both <code>_token_.stop_requested()</code> and <code>_token_.stop_possible()</code> are `constexpr` epxressions yielding `false`. This concept is primarily used to avoid extra work when using stop tokens which will never indicate that cancellations are requested.
339+
The concept <code>unstoppable_token&lt;Token&gt;</code> is modeled by a <code>_Token_</code> if <code>stoppable_token&lt;_Token_&gt;</code> is true and it can statically be determined that both <code>_token_.stop_requested()</code> and <code>_token_.stop_possible()</code> are `constexpr` epxressions yielding `false`. This concept is used to avoid extra work when using stop tokens which will never indicate that cancellations are requested.
340340
<blockquote>
341341
<details>
342342
<summary>Example</summary>
@@ -352,22 +352,117 @@ static_assert(not std::execution::unstoppable_token<std::execution::inline_stop_
352352
</details>
353353

354354
## Queries
355-
The queries are used to obtain properties associated with and object. Except <code><a href=‘#forwarding-query’>forwarding_query</a></code> and <code><a href=‘#get-env’>get_env</a></code> the queries work on <a href=‘#environment’>environments</a>.
355+
The queries are used to obtain properties associated with an object. Except <code><a href=‘#forwarding-query’>forwarding_query</a></code>, <code><a href=‘#get-env’>get_env</a></code>, and <code><a href=‘#get-completion-signatures’>get_completion_signatures</a></code> the queries work on <a href=‘#environment’>environments</a>. The
356+
<a href=‘#environment’>environment</a> queries are defined by providing a member <code>query(<i>query_t</i>, <i>a...</i>) const</code> on the <a href=‘#environment’>environment</a> object.
357+
<details>
358+
<summary>Example defining a query on an environment</summary>
359+
This example shows how to define an environment class which provides a <a href=‘#get-allocator’><code>get_allocator</code></a> query. The objects stores a `std::pmr::memory_resource*` and returns a correspondingly initialized `std::pmr::polymorphic_allocator<>`.
360+
361+
```
362+
struct alloc_env {
363+
std::pmr::memory_resource res{std::pmr::new_delete_resource()};
356364
365+
auto query(get_allocator_t const&) const noexcept {
366+
return std::pmr::polymorphic_allocator<>(this->res);
367+
}
368+
};
369+
```
370+
</details>
357371
<details>
358372
<summary><code>forwarding_query(<i>query</i>) -> bool</code></summary>
373+
**Default**: `false`
374+
<br/>
375+
<code>forwarding_query(<i>query</i>)</code> is a `constexpr` query used to determine if the query <code><i>query</i></code> should be forwarded when wrapping an environment.
376+
<blockquote>
377+
<details>
378+
<summary>Example</summary>
379+
When defining a custom query <code><i>custom</i></code> it is desirable to allow the query getting forwarded. It is necessary to explicit define the result of <code>forwarding_query(<i>custom</i>)</code>. The result can be defined by providing a corresponding `query` member function. When using this approach the function isn’t allowed to throw, needs to return `bool`, and needs to be a core constant expression:
380+
381+
```
382+
struct custom_t {
383+
// ...
384+
constexpr bool query(forwarding_query_t const&) const noexcept {
385+
return true;
386+
}
387+
};
388+
inline constexpr custom_t custom{};
389+
```
390+
391+
Alternatively, the query can be defined as forwarding by deriving publicly from `forwarding_query_t`:
392+
393+
```
394+
struct custom_t: forwarding_query_t {
395+
// ...
396+
};
397+
```
359398
</details>
399+
<blockquote>
400+
</details>
401+
<details>
402+
<summary><code>get_env(<i>queryable</i>) -> <i>env</i></code></summary>
403+
**Default**: <a href='#empty_env'>`empty_env`</a>
404+
<br/>
405+
<code>get_env(<i>queryable</i>)</code> is used to get the environment <code><i>env</i></code> associated with <code><i>queryable</i></code>. To provide a non-default environment for a <code><i>queryable</i></code> a `get_env` member needs to be defined. If <code><i>queryable</i></code> doesn’t provide the <code>get_env</code> query an object of type <code><a href=‘#empty_env’>empty_env</a></code> is returned.
406+
<div>
360407
<details>
361-
<summary><code>get_env(<i>queryable</i>)</code></summary>
408+
<summary>Example</summary>
409+
The example defines an <a href=‘#environment’>environment</a> class <code>env</code> which stores a pointer to the relevant data and is returned as the <a href=‘#environment’>environment</a> for the type `queryable`:
410+
411+
```c++
412+
struct data { /*...*/ };
413+
414+
struct env { data* d; /* ... */ };
415+
416+
struct queryable {
417+
data* d;\
418+
// ...
419+
env get_env() const noexcept { return { this->d }; }
420+
};
421+
```
422+
423+
Note that the `get_env` member is both `const` and `noexcept`.
362424
</details>
425+
</div>
426+
</details>
427+
<details>
428+
<summary><code>get_allocator(<i>env</i>) -> <i>allocator</i></code></summary>
429+
**Default**: <i>none</i>
430+
<br/>
431+
<code>get_allocator(<i>env</i>)</code> returns an <code><i>allocator</i></code> for any memory allocations in the respective context. If <code><i>env</i></code> doesn’t support this query any attempt to access it will result in a compilation error.
432+
<div>
363433
<details>
364-
<summary><code>get_allocator(<i>env</i>)</code></summary>
434+
<summary>Example</summary>
435+
This example shows how to define an environment class which provides a <a href=‘#get-allocator’><code>get_allocator</code></a> query. The objects stores a `std::pmr::memory_resource*` and returns a correspondingly initialized `std::pmr::polymorphic_allocator<>`.
436+
437+
```
438+
struct alloc_env {
439+
std::pmr::memory_resource res{std::pmr::new_delete_resource()};
440+
441+
auto query(get_allocator_t const&) const noexcept {
442+
return std::pmr::polymorphic_allocator<>(this->res);
443+
}
444+
};
445+
```
446+
</details>
447+
</div>
365448
</details>
366449
<details>
367-
<summary><code>get_completion_scheduler(<i>env</i>)</code></summary>
450+
<summary><code>get_completion_scheduler&lt;<i>tag</i>&gt;(<i>env</i>) -> <i>scheduler</i></code></summary>
451+
**Default**: <i>none</i>
452+
<br/>
453+
If the expression <code>get_completion_scheduler&lt;tag&gt;(get_env(<i>sender</i>))</code> is well-formed and returns a scheduler it defines the scheduler on which the completion <code><i>tag</i></code> executes. In particular <code>get_completion_scheduler&lt;set_value_t&gt;(schedule(<i>sched</i>))</code> returns <code><i>sched</i></code>.
368454
</details>
369455
<details>
370456
<summary><code>get_completion_signatures(<i>sender</i>, <i>env</i>)</code></summary>
457+
The expression <code>get_completion_signatures(<i>sender</i>, <i>env</i>)</code> returns an object whose type is a specialization of <a href=‘#completion-signatures’><code>completion_signatures</code></a> defining the possible completion signatures of <code><i>sender</i></code> when connected to a <a href=‘#receiver’><code><i>receiver</i></code></a> whose <a href=‘#environment'>environment</a> <code>get_env(<i>receiver</i>)</code> is <code><i>env</i></code>. A <a href=‘#sender’><code>sender</code></a> can define the result of this query either by defining a member function <code>get_completion_signatures</code> or using a type alias <code>completion_signatures</code>.
458+
<div>
459+
<details>
460+
<summary>Example</summary>
461+
When a <a href=‘#sender’><code>sender</code></a> doesn’t need to compute the completion signatures based on an <a href=‘#environment’>environment</a> it is easiest to use a the type alias:
462+
463+
464+
</details>
465+
</div>
371466
</details>
372467
<details>
373468
<summary><code>get_delegation_scheduler(<i>env</i>)</code></summary>

0 commit comments

Comments
 (0)