Skip to content

Commit 65e70e3

Browse files
committed
added async_scope_token
1 parent 6bb5036 commit 65e70e3

File tree

5 files changed

+158
-0
lines changed

5 files changed

+158
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// include/beman/execution/detail/async_scope_token.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_ASYNC_SCOPE_TOKEN
5+
#define INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_ASYNC_SCOPE_TOKEN
6+
7+
#include <beman/execution/detail/sender.hpp>
8+
#include <beman/execution/detail/sender_in.hpp>
9+
#include <beman/execution/detail/get_completion_signatures.hpp>
10+
#include <concepts>
11+
#include <type_traits>
12+
13+
// ----------------------------------------------------------------------------
14+
15+
namespace beman::execution::detail {
16+
struct token_test_env {};
17+
18+
struct token_test_sender {
19+
using sender_concept = ::beman::execution::sender_t;
20+
auto get_completion_signatures(::beman::execution::detail::token_test_env) const noexcept {
21+
return ::beman::execution::completion_signatures<>{};
22+
}
23+
};
24+
static_assert(::beman::execution::sender<::beman::execution::detail::token_test_sender>);
25+
static_assert(::beman::execution::sender_in<::beman::execution::detail::token_test_sender, ::beman::execution::detail::token_test_env>);
26+
}
27+
28+
namespace beman::execution {
29+
template <typename Token>
30+
concept async_scope_token
31+
= ::std::copyable<Token>
32+
&& requires(Token token) {
33+
{ token.try_associate() } -> ::std::same_as<bool>;
34+
{ token.disassociate() } noexcept;
35+
{ token.wrap(::std::declval<::beman::execution::detail::token_test_sender>()) }
36+
-> ::beman::execution::sender_in<::beman::execution::detail::token_test_env>;
37+
}
38+
;
39+
}
40+
41+
// ----------------------------------------------------------------------------
42+
43+
#endif
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// include/beman/execution/detail/nest.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_NEST
5+
#define INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_NEST
6+
7+
#include <beman/execution/detail/async_scope_token.hpp>
8+
#include <beman/execution/detail/sender.hpp>
9+
10+
// ----------------------------------------------------------------------------
11+
12+
namespace beman::execution {
13+
struct nest_t {
14+
template <::beman::execution::sender Sender, ::beman::execution::async_scope_token Token>
15+
auto operator()(Sender&&, Token&&) const {
16+
}
17+
};
18+
inline constexpr nest_t nest{};
19+
}
20+
21+
// ----------------------------------------------------------------------------
22+
23+
#endif

tests/beman/execution/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ endif()
1111
list(
1212
APPEND
1313
execution_tests
14+
exec-scope-concepts.test
15+
exec-nest.test
1416
issue-144.test
1517
exec-on.test
1618
notify.test
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// tests/beman/execution/exec-nest.test.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <beman/execution/detail/nest.hpp>
5+
#include <test/execution.hpp>
6+
#include <concepts>
7+
8+
// ----------------------------------------------------------------------------
9+
10+
namespace {
11+
struct sender {
12+
using sender_concept = test_std::sender_t;
13+
};
14+
static_assert(test_std::sender<sender>);
15+
static_assert(test_std::sender<sender&>);
16+
static_assert(test_std::sender<sender const&>);
17+
}
18+
19+
TEST(exec_nest) {
20+
static_assert(std::same_as<test_std::nest_t const, decltype(test_std::nest)>);
21+
22+
sender sndr{};
23+
int token{};
24+
//test_std::nest(sndr, token);
25+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// tests/beman/execution/exec-scope-concepts.test.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <beman/execution/detail/async_scope_token.hpp>
5+
#include <beman/execution/detail/sender.hpp>
6+
#include <beman/execution/detail/sender_in.hpp>
7+
#include <beman/execution/detail/completion_signatures.hpp>
8+
#include <beman/execution/detail/set_value.hpp>
9+
#include <test/execution.hpp>
10+
#include <concepts>
11+
#include <utility>
12+
13+
// ----------------------------------------------------------------------------
14+
15+
namespace {
16+
struct sender {
17+
using sender_concept = test_std::sender_t;
18+
};
19+
static_assert(test_std::sender<sender>);
20+
21+
struct copyable {};
22+
static_assert(std::copyable<copyable>);
23+
struct non_copyable {
24+
non_copyable() = default;
25+
non_copyable(non_copyable const&) = delete;
26+
};
27+
static_assert(not std::copyable<non_copyable>);
28+
29+
struct empty {};
30+
31+
template <test_std::sender S>
32+
struct wrap {
33+
using sender_concept = test_std::sender_t;
34+
std::remove_cvref_t<S> sndr;
35+
template <typename E>
36+
auto get_completion_signatures(E const& e) const noexcept {
37+
return test_std::get_completion_signatures(sndr, e);
38+
}
39+
};
40+
static_assert(test_std::sender<wrap<sender>>);
41+
42+
template <test_std::sender>
43+
struct bad {
44+
using sender_concept = test_std::sender_t;
45+
};
46+
47+
48+
template <typename Mem, typename Bool, bool Noexcept, template <test_std::sender> class Wrap>
49+
struct token {
50+
Mem mem{};
51+
auto try_associate() -> Bool { return {}; }
52+
auto disassociate() noexcept(Noexcept) -> void {}
53+
template <test_std::sender Sender>
54+
auto wrap(Sender&& sndr) -> Wrap<Sender> { return Wrap<Sender>(std::forward<Sender>(sndr)); }
55+
};
56+
}
57+
58+
TEST(exec_scope_concepts) {
59+
static_assert(test_std::async_scope_token<token<copyable, bool, true, wrap>>);
60+
static_assert(not test_std::async_scope_token<token<non_copyable, bool, true, wrap>>);
61+
static_assert(not test_std::async_scope_token<token<copyable, int, true, wrap>>);
62+
static_assert(not test_std::async_scope_token<token<copyable, bool, false, wrap>>);
63+
static_assert(not test_std::async_scope_token<token<copyable, bool, true, bad>>);
64+
static_assert(not test_std::async_scope_token<empty>);
65+
}

0 commit comments

Comments
 (0)