Skip to content

Commit 415c13c

Browse files
authored
Merge pull request #4 from beman-project/add-get_domain
Add get domain
2 parents 358802b + 7a3a31a commit 415c13c

File tree

6 files changed

+137
-3
lines changed

6 files changed

+137
-3
lines changed

docs/TODO.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"execution.forwarding_query": { "code":true, "test":true, "doc":false },
88
"execution.get_allocator": { "code":true, "test":true, "doc":false },
99
"execution.get_stop_token": { "code":true, "test":true, "doc":false },
10+
"execution.environment.get_env": { "code":true, "test":true, "doc":false },
11+
"execution.get_domain": { "code":true, "test":true, "doc":false },
1012
"execution.queryable.concepts": { "code":true, "test":true, "doc":false },
1113
"execution.receivers": { "code":true, "test":true, "doc":true, "comment":"empty" },
1214
"execution.senders": { "code":true, "test":true, "doc":true, "comment":"empty" },
@@ -27,7 +29,6 @@
2729
"library": { "code":true, "test":true, "doc":true, "comment":"term definition only" },
2830
"support": { "code":true, "test":true, "doc":true, "comment":"empty" },
2931
"support.limits": { "code":true, "test":true, "doc":true, "comment":"empty" },
30-
"exec.get.env": { "code":true, "test":true, "doc":false },
3132
"utilities": { "code":true, "test":true, "doc":true, "comment":"empty" },
3233
"function.objects": { "code":true, "test":true, "doc":true, "comment":"empty" },
3334
"functional.syn": { "code":true, "test":true, "doc":false },

docs/TODO.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
| [[execution.forwarding_query](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.forwarding_query)] | ✅ | ✅ | 🔴 | |
5353
| [[execution.get_allocator](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_allocator)] | ✅ | ✅ | 🔴 | |
5454
| [[execution.get_stop_token](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_stop_token)] | ✅ | ✅ | 🔴 | |
55-
| [[execution.environment.get_env](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.environment.get_env)] | 🔴 | 🔴 | 🔴 | |
56-
| [[execution.get_domain](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_domain)] | 🔴 | 🔴 | 🔴 | |
55+
| [[execution.environment.get_env](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.environment.get_env)] | ✅ | ✅ | 🔴 | |
56+
| [[execution.get_domain](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_domain)] | ✅ | ✅ | 🔴 | |
5757
| [[execution.get_scheduler](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_scheduler)] | 🔴 | 🔴 | 🔴 | |
5858
| [[execution.get_delegation_scheduler](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_delegation_scheduler)] | 🔴 | 🔴 | 🔴 | |
5959
| [[execution.get_forward_progress_guarantee](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.get_forward_progress_guarantee)] | 🔴 | 🔴 | 🔴 | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// include/Beman/Execution26/detail/get_domain.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_GET_DOMAIN
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_GET_DOMAIN
6+
7+
#include <Beman/Execution26/detail/common.hpp>
8+
#include <Beman/Execution26/detail/forwarding_query.hpp>
9+
#include <utility>
10+
11+
// ----------------------------------------------------------------------------
12+
13+
namespace Beman::Execution26
14+
{
15+
struct get_domain_t
16+
{
17+
template <typename Object>
18+
requires (not requires(Object&& object, get_domain_t const& tag)
19+
{
20+
::std::forward<Object>(object).query(tag);
21+
})
22+
&& (not requires(Object&& object, get_domain_t const& tag)
23+
{
24+
::std::as_const(object).query(tag);
25+
})
26+
auto operator()(Object&&) const noexcept
27+
= BEMAN_EXECUTION26_DELETE("object neeeds a query(get_domain_t) overload");
28+
template <typename Object>
29+
requires (not requires(Object&& object, get_domain_t const& tag)
30+
{
31+
::std::as_const(object).query(tag);
32+
})
33+
auto operator()(Object&&) const noexcept
34+
= BEMAN_EXECUTION26_DELETE("query(get_domain_t) overload needs to be const");
35+
template <typename Object>
36+
requires (not requires(Object&& object, get_domain_t const& tag)
37+
{
38+
{ ::std::as_const(object).query(tag) } noexcept;
39+
})
40+
auto operator()(Object&&) const noexcept
41+
= BEMAN_EXECUTION26_DELETE("query(get_domain_t) overload needs to be noexcept");
42+
43+
template <typename Object>
44+
constexpr auto operator()(Object&& object) const noexcept
45+
{
46+
return ::std::as_const(object).query(*this);
47+
}
48+
constexpr auto query(::Beman::Execution26::forwarding_query_t const&) const noexcept -> bool
49+
{
50+
return true;
51+
}
52+
};
53+
54+
inline constexpr get_domain_t get_domain{};
55+
}
56+
57+
// ----------------------------------------------------------------------------
58+
59+
#endif

include/Beman/Execution26/execution.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <Beman/Execution26/detail/get_allocator.hpp>
1212
#include <Beman/Execution26/detail/get_stop_token.hpp>
1313
#include <Beman/Execution26/detail/get_env.hpp>
14+
#include <Beman/Execution26/detail/get_domain.hpp>
1415

1516
#include <Beman/Execution26/detail/completion_signature.hpp>
1617
#include <Beman/Execution26/detail/completion_signatures.hpp>

src/Beman/Execution26/tests/CMakeLists.txt

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

44
list(APPEND execution_tests
5+
exec-get-domain.pass
56
exec-get-stop-token.pass
67
exec-get-allocator.pass
78
exec-fwd-env.pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// src/Beman/Execution26/tests/exec-get-domain.pass.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <Beman/Execution26/execution.hpp>
5+
#include <test/execution.hpp>
6+
#include <concepts>
7+
8+
// ----------------------------------------------------------------------------
9+
10+
namespace
11+
{
12+
struct domain { int value{}; };
13+
14+
struct no_get_domain {};
15+
16+
template <bool Noexcept>
17+
struct non_const_get_domain
18+
{
19+
auto query(test_std::get_domain_t const&) noexcept(Noexcept) -> domain
20+
{
21+
return {};
22+
}
23+
};
24+
25+
26+
template <bool Noexcept, typename Result>
27+
struct has_get_domain
28+
{
29+
int value{};
30+
constexpr auto query(test_std::get_domain_t const&) const noexcept(Noexcept) -> Result
31+
{
32+
return {this->value};
33+
}
34+
};
35+
36+
struct overloaded_get_domain
37+
{
38+
auto query(test_std::get_domain_t const&) const noexcept -> domain
39+
{
40+
return {};
41+
}
42+
auto query(test_std::get_domain_t const&) noexcept -> void = delete;
43+
};
44+
45+
template <bool Expect, typename Result, typename Object>
46+
auto test_get_domain(Object&& object)
47+
{
48+
static_assert(Expect == requires{ test_std::get_domain(object); });
49+
if constexpr (requires{ test_std::get_domain(object); })
50+
{
51+
static_assert(std::same_as<Result, decltype(test_std::get_domain(object))>);
52+
}
53+
}
54+
}
55+
56+
auto main() -> int
57+
{
58+
static_assert(std::same_as<test_std::get_domain_t const,
59+
decltype(test_std::get_domain)>);
60+
61+
static_assert(test_std::forwarding_query(test_std::get_domain));
62+
63+
test_get_domain<false, bool>(no_get_domain{});
64+
test_get_domain<false, bool>(non_const_get_domain<true>{});
65+
test_get_domain<false, bool>(non_const_get_domain<false>{});
66+
test_get_domain<true, domain>(has_get_domain<true, domain>{42});
67+
test_get_domain<false, bool>(has_get_domain<false, domain>{42});
68+
test_get_domain<true, domain>(overloaded_get_domain{});
69+
70+
assert(42 == test_std::get_domain(has_get_domain<true, domain>{42}).value);
71+
static_assert(42 == test_std::get_domain(has_get_domain<true, domain>{42}).value);
72+
}

0 commit comments

Comments
 (0)