-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
basic: add Sender, Receives and Operation concepts
- Loading branch information
1 parent
d5f9f08
commit 06dacf5
Showing
6 changed files
with
205 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# `concept Operation` | ||
|
||
The `Operation` concept holds all the requirements for an | ||
[operation](/sender-receiver.md). | ||
|
||
## Prototype | ||
|
||
```cpp | ||
template<typename T> | ||
concept Operation = ...; | ||
``` | ||
|
||
### Requirements | ||
|
||
`T` can be started via the [start\_inline](/headers/execution.md) CPO. | ||
|
||
## Examples | ||
|
||
```cpp | ||
template <typename Receiver> | ||
struct write_operation { | ||
write_operation(write_sender s, Receiver r) | ||
: req_{}, handle_{s.handle}, bufs_{s.bufs}, nbufs_{s.nbufs}, r_{std::move(r)} { } | ||
|
||
write_operation(const write_operation &) = delete; | ||
write_operation &operator=(const write_operation &) = delete; | ||
write_operation(write_operation &&) = delete; | ||
write_operation &operator=(write_operation &&) = delete; | ||
|
||
bool start_inline() { /* omitted for brevity */ } | ||
|
||
private: | ||
uv_write_t req_; | ||
uv_stream_t *handle_; | ||
const uv_buf_t *bufs_; | ||
size_t nbufs_; | ||
|
||
Receiver r_; | ||
}; | ||
static_assert(async::Operation<write_operation<noop_receiver>>); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# `concept Receives` | ||
|
||
The `Receives<T>` concept holds all the requirements for a | ||
[receiver](/sender-receiver.md) that can receive a `T` value (or none, when `T` | ||
is `void`). | ||
|
||
## Prototype | ||
|
||
```cpp | ||
template<typename T, typename Receives> | ||
concept Receives = ...; | ||
``` | ||
|
||
### Requirements | ||
|
||
A `set_value_inline` and `set_value_noinline` members, which can be called with | ||
a `T&&` value, or no parameters, if `T` is `void`. | ||
|
||
## Examples | ||
|
||
```cpp | ||
struct discard_receiver { | ||
template<typename T> | ||
void set_value_inline(T) { | ||
assert(std::is_constant_evaluated()); | ||
} | ||
void set_value_inline() { | ||
assert(std::is_constant_evaluated()); | ||
} | ||
|
||
template<typename T> | ||
void set_value_noinline(T) { | ||
assert(std::is_constant_evaluated()); | ||
} | ||
void set_value_noinline() { | ||
assert(std::is_constant_evaluated()); | ||
} | ||
}; | ||
static_assert(async::Receives<discard_receiver, void>); | ||
static_assert(async::Receives<discard_receiver, int>); | ||
static_assert(async::Receives<discard_receiver, std::string>); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# `concept Sender` | ||
|
||
The `Sender` concept holds all the requirements for a | ||
[sender](/sender-receiver.md). | ||
|
||
## Prototype | ||
|
||
```cpp | ||
template<typename T> | ||
concept Sender = ...; | ||
``` | ||
|
||
### Requirements | ||
|
||
`T` has a `value_type`, is move constructible, and can be | ||
[connected](/headers/execution.md). | ||
|
||
## Examples | ||
|
||
```cpp | ||
struct [[nodiscard]] write_sender { | ||
using value_type = int; // Status code | ||
|
||
uv_stream_t *handle; | ||
const uv_buf_t *bufs; | ||
size_t nbufs; | ||
}; | ||
|
||
/* operation omitted for brevity */ | ||
template <typename Receiver> | ||
/*operation*/<Receiver> connect(write_sender s, Receiver r) { | ||
return {s, std::move(r)}; | ||
} | ||
static_assert(async::Sender<write_sender>); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters