Skip to content

Commit 3fd5d0a

Browse files
committed
added get_completion_scheduler, get_scheduler, sched_attrs, and sched_env
1 parent ada4e41 commit 3fd5d0a

9 files changed

+361
-1
lines changed

include/Beman/Execution26/detail/forwarding_query.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_FORWARDING_QUERY
66

77
#include <concepts>
8+
#include <type_traits>
89
#include <utility>
910

1011
// ----------------------------------------------------------------------------
@@ -25,7 +26,7 @@ namespace Beman::Execution26
2526
template <typename Object>
2627
constexpr auto operator()(Object&&) const noexcept -> bool
2728
{
28-
return ::std::derived_from<Object, ::Beman::Execution26::forwarding_query_t>;
29+
return ::std::derived_from<::std::remove_cvref_t<Object>, ::Beman::Execution26::forwarding_query_t>;
2930
}
3031
};
3132

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// include/Beman/Execution26/detail/get_completion_scheduler.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_GET_COMPLETION_SCHEDULER
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_GET_COMPLETION_SCHEDULER
6+
7+
#include <Beman/Execution26/detail/forwarding_query.hpp>
8+
#include <Beman/Execution26/detail/set_error.hpp>
9+
#include <Beman/Execution26/detail/set_stopped.hpp>
10+
#include <Beman/Execution26/detail/set_value.hpp>
11+
#include <concepts>
12+
#include <type_traits>
13+
#include <utility>
14+
15+
// ----------------------------------------------------------------------------
16+
17+
namespace Beman::Execution26
18+
{
19+
template <typename Tag>
20+
struct get_completion_scheduler_t
21+
: ::Beman::Execution26::forwarding_query_t
22+
{
23+
template <typename Env>
24+
auto operator()(Env&& env) const noexcept
25+
{
26+
static_assert(noexcept(::std::as_const(env).query(*this)));
27+
//-dk:TODO mandate result is a scheduler:
28+
// static_assert(::Beman::Execution26::scheduler<
29+
// decltype(::std::as_const(env).query(*this))
30+
// >);
31+
return ::std::as_const(env).query(*this);
32+
}
33+
};
34+
35+
template <typename Tag>
36+
requires(
37+
::std::same_as<Tag, ::Beman::Execution26::set_error_t>
38+
|| ::std::same_as<Tag, ::Beman::Execution26::set_stopped_t>
39+
|| ::std::same_as<Tag, ::Beman::Execution26::set_value_t>
40+
)
41+
inline constexpr get_completion_scheduler_t<Tag> get_completion_scheduler{};
42+
}
43+
44+
// ----------------------------------------------------------------------------
45+
46+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// include/Beman/Execution26/detail/get_scheduler.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_GET_SCHEDULER
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_GET_SCHEDULER
6+
7+
#include <Beman/Execution26/detail/forwarding_query.hpp>
8+
#include <utility>
9+
10+
// ----------------------------------------------------------------------------
11+
12+
namespace Beman::Execution26
13+
{
14+
struct get_scheduler_t
15+
: ::Beman::Execution26::forwarding_query_t
16+
{
17+
template <typename Env>
18+
auto operator()(Env&& env) const noexcept
19+
{
20+
static_assert(noexcept(::std::as_const(env).query(*this)));
21+
//-dk:TODO mandate that the result is a scheduler
22+
// static_assert(::Beman::Execution26::scheduler<
23+
// decltype(::std::as_const(env).query(*this))
24+
// >)
25+
return ::std::as_const(env).query(*this);
26+
}
27+
};
28+
29+
inline constexpr get_scheduler_t get_scheduler{};
30+
}
31+
32+
// ----------------------------------------------------------------------------
33+
34+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// include/Beman/Execution26/detail/sched_attrs.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_SCHED_ATTRS
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_SCHED_ATTRS
6+
7+
#include <Beman/Execution26/detail/get_domain.hpp>
8+
#include <Beman/Execution26/detail/get_completion_scheduler.hpp>
9+
#include <Beman/Execution26/detail/set_error.hpp>
10+
#include <Beman/Execution26/detail/set_stopped.hpp>
11+
#include <Beman/Execution26/detail/set_value.hpp>
12+
#include <concepts>
13+
#include <type_traits>
14+
#include <utility>
15+
16+
// ----------------------------------------------------------------------------
17+
18+
namespace Beman::Execution26::Detail
19+
{
20+
template <typename Scheduler>
21+
class sched_attrs
22+
{
23+
private:
24+
Scheduler sched;
25+
26+
public:
27+
template <typename S>
28+
sched_attrs(S&& sched): sched(::std::forward<S>(sched)) {}
29+
30+
template <typename Tag>
31+
auto query(::Beman::Execution26::get_completion_scheduler_t<Tag> const&) const noexcept
32+
{
33+
return this->sched;
34+
}
35+
auto query(::Beman::Execution26::get_domain_t const& q) const noexcept
36+
{
37+
return this->sched.query(q);
38+
}
39+
};
40+
41+
template <typename Scheduler>
42+
sched_attrs(Scheduler&&) -> sched_attrs<::std::remove_cvref_t<Scheduler>>;
43+
}
44+
45+
// ----------------------------------------------------------------------------
46+
47+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// include/Beman/Execution26/detail/sched_env.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_SCHED_ENV
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_SCHED_ENV
6+
7+
#include <Beman/Execution26/detail/get_domain.hpp>
8+
#include <Beman/Execution26/detail/get_scheduler.hpp>
9+
#include <type_traits>
10+
#include <utility>
11+
12+
// ----------------------------------------------------------------------------
13+
14+
namespace Beman::Execution26::Detail
15+
{
16+
template <typename Scheduler>
17+
class sched_env
18+
{
19+
private:
20+
Scheduler sched;
21+
22+
public:
23+
template <typename S>
24+
sched_env(S&& sched): sched(::std::forward<S>(sched)) {}
25+
26+
auto query(::Beman::Execution26::get_scheduler_t const&) const noexcept
27+
{
28+
return this->sched;
29+
}
30+
auto query(::Beman::Execution26::get_domain_t const& q) const noexcept
31+
{
32+
return this->sched.query(q);
33+
}
34+
};
35+
36+
template <typename Scheduler>
37+
sched_env(Scheduler&&) -> sched_env<::std::remove_cvref_t<Scheduler>>;
38+
}
39+
40+
// ----------------------------------------------------------------------------
41+
42+
#endif

src/Beman/Execution26/tests/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
list(APPEND execution_tests
5+
exec-get-scheduler.pass
6+
exec-get-compl-sched.pass
57
exec-snd-expos.pass
68
exec-snd-concepts.pass
79
exec-getcomplsigs.pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// src/Beman/Execution26/tests/exec-get-compl-sched.pass.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <Beman/Execution26/detail/get_completion_scheduler.hpp>
5+
#include <Beman/Execution26/detail/forwarding_query.hpp>
6+
#include <Beman/Execution26/detail/set_error.hpp>
7+
#include <Beman/Execution26/detail/set_stopped.hpp>
8+
#include <Beman/Execution26/detail/set_value.hpp>
9+
#include <concepts>
10+
#include <test/execution.hpp>
11+
12+
// ----------------------------------------------------------------------------
13+
14+
namespace
15+
{
16+
struct tag {};
17+
18+
template <typename Tag>
19+
struct scheduler
20+
{
21+
int value{};
22+
auto operator== (scheduler const&) const -> bool = default;
23+
};
24+
25+
struct env
26+
{
27+
int value{};
28+
auto query(test_std::get_completion_scheduler_t<test_std::set_value_t> const&) const noexcept
29+
{
30+
return scheduler<test_std::set_value_t>{this->value + 1};
31+
}
32+
auto query(test_std::get_completion_scheduler_t<test_std::set_error_t> const&) const noexcept
33+
{
34+
return scheduler<test_std::set_error_t>{this->value + 2};
35+
}
36+
auto query(test_std::get_completion_scheduler_t<test_std::set_stopped_t> const&) const noexcept
37+
{
38+
return scheduler<test_std::set_stopped_t>{this->value + 3};
39+
}
40+
template <typename Tag>
41+
auto query(test_std::get_completion_scheduler_t<Tag> const&) const noexcept
42+
{
43+
return scheduler<Tag>{this->value};
44+
}
45+
};
46+
47+
template <bool Expect, typename Tag, typename Env>
48+
auto test_tag(Env&& env) -> void
49+
{
50+
static_assert(Expect == requires{ test_std::get_completion_scheduler<Tag>(env); });
51+
}
52+
}
53+
54+
auto main() -> int
55+
{
56+
static_assert(std::same_as<test_std::get_completion_scheduler_t<test_std::set_error_t> const,
57+
decltype(test_std::get_completion_scheduler<test_std::set_error_t>)>);
58+
static_assert(std::same_as<test_std::get_completion_scheduler_t<test_std::set_stopped_t> const,
59+
decltype(test_std::get_completion_scheduler<test_std::set_stopped_t>)>);
60+
static_assert(std::same_as<test_std::get_completion_scheduler_t<test_std::set_value_t> const,
61+
decltype(test_std::get_completion_scheduler<test_std::set_value_t>)>);
62+
static_assert(test_std::forwarding_query(test_std::get_completion_scheduler<test_std::set_error_t>));
63+
static_assert(test_std::forwarding_query(test_std::get_completion_scheduler<test_std::set_stopped_t>));
64+
static_assert(test_std::forwarding_query(test_std::get_completion_scheduler<test_std::set_value_t>));
65+
66+
env e{17};
67+
test_tag<true, test_std::set_error_t>(e);
68+
test_tag<true, test_std::set_stopped_t>(e);
69+
test_tag<true, test_std::set_value_t>(e);
70+
test_tag<false, tag>(e);
71+
72+
static_assert(::std::same_as<
73+
decltype(test_std::get_completion_scheduler<test_std::set_error_t>(e)),
74+
scheduler<test_std::set_error_t>>);
75+
static_assert(::std::same_as<
76+
decltype(test_std::get_completion_scheduler<test_std::set_stopped_t>(e)),
77+
scheduler<test_std::set_stopped_t>>);
78+
static_assert(::std::same_as<
79+
decltype(test_std::get_completion_scheduler<test_std::set_value_t>(e)),
80+
scheduler<test_std::set_value_t>>);
81+
assert(test_std::get_completion_scheduler<test_std::set_error_t>(e)
82+
== scheduler<test_std::set_error_t>{19});
83+
assert(test_std::get_completion_scheduler<test_std::set_stopped_t>(e)
84+
== scheduler<test_std::set_stopped_t>{20});
85+
assert(test_std::get_completion_scheduler<test_std::set_value_t>(e)
86+
== scheduler<test_std::set_value_t>{18});
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// src/Beman/Execution26/tests/exec-get-scheduler.pass.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <Beman/Execution26/detail/get_scheduler.hpp>
5+
#include <Beman/Execution26/detail/forwarding_query.hpp>
6+
#include <test/execution.hpp>
7+
#include <concepts>
8+
9+
// ----------------------------------------------------------------------------
10+
11+
namespace
12+
{
13+
struct scheduler
14+
{
15+
int value{};
16+
auto operator== (scheduler const&) const -> bool = default;
17+
};
18+
19+
struct env
20+
{
21+
int value{};
22+
auto query(test_std::get_scheduler_t const&) const noexcept
23+
{
24+
return scheduler{this->value};
25+
}
26+
};
27+
}
28+
29+
auto main() -> int
30+
{
31+
static_assert(std::same_as<test_std::get_scheduler_t const,
32+
decltype(test_std::get_scheduler)>);
33+
static_assert(test_std::forwarding_query(test_std::get_scheduler));
34+
env e{17};
35+
auto sched{test_std::get_scheduler(e)};
36+
static_assert(::std::same_as<scheduler, decltype(sched)>);
37+
assert(sched == scheduler{17});
38+
}

0 commit comments

Comments
 (0)