Skip to content

Commit d5a84cf

Browse files
committed
added exec.prop
1 parent 131457b commit d5a84cf

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// include/beman/execution/detail/prop.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_PROP
5+
#define INCLUDED_INCLUDE_BEMAN_EXECUTION_DETAIL_PROP
6+
7+
#include <type_traits>
8+
9+
// ----------------------------------------------------------------------------
10+
11+
namespace beman::execution {
12+
template <typename Query, typename Value>
13+
struct prop {
14+
[[no_unique_address]] Query query_;
15+
Value value_;
16+
17+
auto operator=(prop const&) = delete;
18+
19+
constexpr auto query(Query) const noexcept -> Value { return this->value_; }
20+
};
21+
22+
template <typename Query, typename Value>
23+
prop(Query, Value) -> prop<Query, ::std::unwrap_reference_t<Value>>;
24+
}
25+
26+
// ----------------------------------------------------------------------------
27+
28+
#endif

src/beman/execution/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ target_sources(
135135
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/operation_state.hpp
136136
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/operation_state_task.hpp
137137
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/product_type.hpp
138+
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/prop.hpp
138139
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/query_with_default.hpp
139140
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/queryable.hpp
140141
${PROJECT_SOURCE_DIR}/include/beman/execution/detail/read_env.hpp

tests/beman/execution/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ endif()
1111
list(
1212
APPEND
1313
execution_tests
14+
exec-prop.test
1415
exec-scope-simple-counting.test
1516
exec-spawn-future.test
1617
exec-scope-concepts.test
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// tests/beman/execution/exec-prop.test.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <beman/execution/detail/prop.hpp>
5+
#include <beman/execution/detail/forwarding_query.hpp>
6+
#include <type_traits>
7+
#include <concepts>
8+
#include <test/execution.hpp>
9+
10+
// ----------------------------------------------------------------------------
11+
12+
namespace {
13+
constexpr struct test_query_t {
14+
template <typename Env>
15+
requires requires(const test_query_t& self, const Env& e) { e.query(self); }
16+
decltype(auto) operator()(const Env& e) const noexcept(noexcept(e.query(*this))) {
17+
return e.query(*this);
18+
}
19+
constexpr auto query(const test_std::forwarding_query_t&) const noexcept -> bool { return true; }
20+
} test_query{};
21+
22+
struct env {
23+
auto query(test_query_t const&) const noexcept { return 42; }
24+
};
25+
26+
template <typename Env, typename Value>
27+
auto test_prop(Env&& env, Value&& value) {
28+
static_assert(requires{ { test_query(env) } noexcept; });
29+
ASSERT(test_query(env) == value);
30+
}
31+
}
32+
33+
TEST(exec_prop) {
34+
test_prop(env{}, 42);
35+
test_prop(test_std::prop(test_query, 42), 42);
36+
[[maybe_unused]] auto p{test_std::prop(test_query, 2.5)};
37+
static_assert(not std::is_assignable_v<decltype(p), decltype(p)>);
38+
}
39+

0 commit comments

Comments
 (0)