Skip to content

Commit 6380044

Browse files
authored
Merge pull request #1654 from RobertLeahy/write_env_20250927
write_env: No Evaluated Context for Environment Type
2 parents 27398a4 + 6613b75 commit 6380044

File tree

3 files changed

+71
-4
lines changed

3 files changed

+71
-4
lines changed

include/stdexec/__detail/__write_env.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ namespace stdexec {
6161
stdexec::get_env(__child));
6262
};
6363

64-
static constexpr auto get_env =
65-
[](__ignore, const auto& __state, const auto& __rcvr) noexcept {
66-
return __env::__join(__state, stdexec::get_env(__rcvr));
67-
};
64+
static constexpr auto get_env = [](__ignore, const auto& __state, const auto& __rcvr) noexcept
65+
-> decltype(__env::__join(__state, stdexec::get_env(__rcvr))) {
66+
return __env::__join(__state, stdexec::get_env(__rcvr));
67+
};
6868

6969
static constexpr auto get_completion_signatures =
7070
[]<class _Self, class... _Env>(_Self &&, _Env &&...) noexcept

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ set(stdexec_test_sources
5555
stdexec/algos/adaptors/test_stopped_as_optional.cpp
5656
stdexec/algos/adaptors/test_stopped_as_error.cpp
5757
stdexec/algos/adaptors/test_ensure_started.cpp
58+
stdexec/algos/adaptors/test_write_env.cpp
5859
stdexec/algos/consumers/test_start_detached.cpp
5960
stdexec/algos/consumers/test_sync_wait.cpp
6061
stdexec/algos/other/test_execute.cpp
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
* Copyright (c) 2025 Robert Leahy. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
*
6+
* Licensed under the Apache License, Version 2.0 with LLVM Exceptions (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://llvm.org/LICENSE.txt
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include <catch2/catch.hpp>
20+
21+
#include <utility>
22+
#include <type_traits>
23+
24+
#include <stdexec/execution.hpp>
25+
#include <test_common/receivers.hpp>
26+
27+
namespace {
28+
29+
template <typename T>
30+
struct receiver : expect_void_receiver<> {
31+
constexpr ::stdexec::env<> get_env() const noexcept {
32+
return state_->get_env();
33+
}
34+
T* state_;
35+
};
36+
37+
struct state;
38+
39+
static_assert(!std::is_same_v<
40+
void,
41+
decltype(::stdexec::connect(
42+
::stdexec::just()
43+
| ::stdexec::write_env(::stdexec::prop{
44+
::stdexec::get_stop_token,
45+
std::declval<::stdexec::inplace_stop_source&>().get_token()}),
46+
receiver<state>{{}, nullptr}))>);
47+
48+
struct state {
49+
constexpr ::stdexec::env<> get_env() const noexcept {
50+
return {};
51+
}
52+
};
53+
54+
TEST_CASE(
55+
"write_env works when the actual environment is sourced from a type which was initially "
56+
"incomplete but has since been completed",
57+
"[adaptors][write_env]") {
58+
::stdexec::inplace_stop_source source;
59+
state s;
60+
auto op = ::stdexec::connect(
61+
::stdexec::just()
62+
| ::stdexec::write_env(::stdexec::prop{::stdexec::get_stop_token, source.get_token()}),
63+
receiver<state>{{}, &s});
64+
::stdexec::start(op);
65+
}
66+
} // namespace

0 commit comments

Comments
 (0)