Skip to content

Commit 8f6a1f9

Browse files
committed
added forwarding_query
1 parent 0ba61a9 commit 8f6a1f9

File tree

7 files changed

+124
-2
lines changed

7 files changed

+124
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ e.g.:
3636

3737
| Library | Linux | MacOS | Windows |
3838
| ------- | ----- | ----- | ------- |
39-
| build | ![Linux build status](https://github.com/dietmarkuehl/beman-execution/actions/workflows/linux.yml/badge.svg) | ![MacOS build status](https://github.com/dietmarkuehl/beman-execution/actions/workflows/macos.yml/badge.svg) | ![Window build status](https://github.com/dietmarkuehl/beman-execution/actions/workflows/windows.yml/badge.svg) |
39+
| build | ![Linux build status](https://github.com/beman-project/Execution26/actions/workflows/linux.yml/badge.svg) | ![MacOS build status](https://github.com/beman-project/Execution26/actions/workflows/macos.yml/badge.svg) | ![Window build status](https://github.com/beman-project/Execution26/actions/workflows/windows.yml/badge.svg) |
4040

4141
You can just use `make` in the current directory. It will invoke `cmake`,
4242
build the code, and run tests. To have more control over the build-process

docs/TODO.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"execution.queries": { "code":true, "test":true, "doc":true, "comment":"empty" },
55
"execution.queryable": { "code":true, "test":true, "doc":true, "comment":"empty" },
66
"execution.queryable.general]": { "code":true, "test":true, "doc":false, "comment":"nothing testable" },
7+
"execution.forwarding_query": { "code":true, "test":true, "doc":false },
78
"execution.queryable.concepts": { "code":true, "test":true, "doc":false },
89
"execution.receivers": { "code":true, "test":true, "doc":true, "comment":"empty" },
910
"execution.senders": { "code":true, "test":true, "doc":true, "comment":"empty" },

docs/TODO.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
| [[execution-async.ops](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution-async.ops)] | 🔴 | 🔴 | 🔴 | |
5050
| [[execution.syn](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.syn)] | 🔴 | 🔴 | 🔴 | |
5151
| [[execution.queries](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.queries)] | ✅ | ✅ | ✅ | empty |
52-
| [[execution.forwarding_query](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.forwarding_query)] | 🔴 | 🔴 | 🔴 | |
52+
| [[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)] | 🔴 | 🔴 | 🔴 | |
5555
| [[execution.environment.get_env](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2300r10.html#execution.environment.get_env)] | 🔴 | 🔴 | 🔴 | |

docs/questions.md

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ likely observable.
1212
- [exec.general] use "Mandates: err != exception_ptr() is true."
1313
However, the condition can only be determined at run-time =>
1414
The "Mandates" should be "Precondition".
15+
- [exec.fwd.env] states "Mandates: ... is a core constant expression if
16+
`q` is a core constant expression": I don't know how to possibly
17+
implement that.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// include/Beman/Execution26/detail/forwarding_query.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_FORWARDING_QUERY
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_FORWARDING_QUERY
6+
7+
#include <concepts>
8+
#include <utility>
9+
10+
// ----------------------------------------------------------------------------
11+
12+
namespace Beman::Execution26
13+
{
14+
struct forwarding_query_t
15+
{
16+
template <typename Object>
17+
requires requires(Object&& object, forwarding_query_t const& query)
18+
{
19+
{ ::std::forward<Object>(object).query(query) } noexcept -> ::std::same_as<bool>;
20+
}
21+
constexpr auto operator()(Object&& object) const noexcept -> bool
22+
{
23+
return ::std::forward<Object>(object).query(*this);
24+
}
25+
template <typename Object>
26+
constexpr auto operator()(Object&&) const noexcept -> bool
27+
{
28+
return ::std::derived_from<Object, ::Beman::Execution26::forwarding_query_t>;
29+
}
30+
};
31+
32+
inline constexpr forwarding_query_t forwarding_query{};
33+
}
34+
35+
// ----------------------------------------------------------------------------
36+
37+
#endif

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-fwd-env.pass
56
exec-opstate.pass
67
exec-opstate-start.pass
78
allocator-requirements-general.pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// src/Beman/Execution26/tests/exec-fwd-env.pass.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <Beman/Execution26/detail/forwarding_query.hpp>
5+
#include <Beman/Execution26/execution.hpp>
6+
#include <test/execution.hpp>
7+
#include <concepts>
8+
9+
// ----------------------------------------------------------------------------
10+
11+
namespace
12+
{
13+
struct derived
14+
: test_std::forwarding_query_t
15+
{
16+
};
17+
18+
template <bool Noexcept = true, typename Result = bool, Result Value = true>
19+
struct static_query
20+
{
21+
constexpr auto query(test_std::forwarding_query_t) noexcept(Noexcept) -> Result
22+
{
23+
return Value;
24+
}
25+
};
26+
27+
struct rvalue_query
28+
{
29+
constexpr auto query(test_std::forwarding_query_t) && noexcept -> bool
30+
{
31+
return true;
32+
}
33+
};
34+
35+
struct const_query
36+
{
37+
constexpr auto query(test_std::forwarding_query_t&&) noexcept -> bool = delete;
38+
constexpr auto query(test_std::forwarding_query_t&) noexcept -> bool = delete;
39+
constexpr auto query(test_std::forwarding_query_t const&) noexcept -> bool
40+
{
41+
return true;
42+
}
43+
};
44+
45+
struct dynamic_query
46+
{
47+
bool value{true};
48+
constexpr auto query(test_std::forwarding_query_t) && noexcept -> bool
49+
{
50+
return value;
51+
}
52+
};
53+
}
54+
55+
auto main(int ac, char*[]) -> int
56+
{
57+
static_assert(std::same_as<test_std::forwarding_query_t const,
58+
decltype(test_std::forwarding_query)>);
59+
60+
static_assert(not test_std::forwarding_query(0));
61+
static_assert(test_std::forwarding_query(derived()));
62+
static_assert(test_std::forwarding_query(static_query<>()));
63+
static_assert(not test_std::forwarding_query(static_query<false>()));
64+
static_assert(not test_std::forwarding_query(static_query<true, int>()));
65+
static_assert(not test_std::forwarding_query(static_query<true, bool, false>()));
66+
67+
static_assert(test_std::forwarding_query(rvalue_query()));
68+
rvalue_query rq{};
69+
static_assert(not test_std::forwarding_query(rq));
70+
rvalue_query crq{};
71+
static_assert(not test_std::forwarding_query(crq));
72+
73+
static_assert(test_std::forwarding_query(const_query()));
74+
75+
static_assert(test_std::forwarding_query(dynamic_query()));
76+
static_assert(test_std::forwarding_query(dynamic_query{true}));
77+
static_assert(not test_std::forwarding_query(dynamic_query{false}));
78+
assert(test_std::forwarding_query(dynamic_query{ac == 1}));
79+
assert(not test_std::forwarding_query(dynamic_query{ac != 1}));
80+
}

0 commit comments

Comments
 (0)