From c230a41d6a7b13196502581c7454e415128be33c Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Wed, 26 Mar 2025 09:42:34 -0700 Subject: [PATCH 1/2] clean up `_rcvr_with_env_t` and fix portability issues --- include/ustdex/detail/rcvr_with_env.hpp | 109 +++++----------- include/ustdex/detail/receiver_with_env.hpp | 133 -------------------- include/ustdex/detail/starts_on.hpp | 23 +--- 3 files changed, 34 insertions(+), 231 deletions(-) delete mode 100644 include/ustdex/detail/receiver_with_env.hpp diff --git a/include/ustdex/detail/rcvr_with_env.hpp b/include/ustdex/detail/rcvr_with_env.hpp index bb5f724..ced06cf 100644 --- a/include/ustdex/detail/rcvr_with_env.hpp +++ b/include/ustdex/detail/rcvr_with_env.hpp @@ -28,107 +28,54 @@ namespace ustdex template struct _rcvr_with_env_t : Rcvr { - using _env_t = _rcvr_with_env_t const&; - - USTDEX_TRIVIAL_API auto _rcvr() noexcept -> Rcvr& - { - return *this; - } - - USTDEX_TRIVIAL_API auto _rcvr() const noexcept -> const Rcvr& + struct _env_t { - return *this; - } - - USTDEX_TRIVIAL_API auto get_env() const noexcept -> _env_t - { - return _env_t{*this}; - } - - template - USTDEX_TRIVIAL_API static constexpr decltype(auto) _get_1st(const _rcvr_with_env_t& _self) noexcept - { - if constexpr (_queryable_with) + template + USTDEX_TRIVIAL_API static constexpr decltype(auto) _get_1st(const _env_t& self) noexcept { - return (_self._env_); + if constexpr (_queryable_with) + { + return (self._rcvr_->_env_); + } + else if constexpr (_queryable_with, Query>) + { + return ustdex::get_env(static_cast(*self._rcvr_)); + } } - else if constexpr (_queryable_with, Query>) - { - return ustdex::get_env(static_cast(_self)); - } - } - template - using _1st_env_t = decltype(_rcvr_with_env_t::_get_1st(declval())); + template + using _1st_env_t = decltype(_env_t::_get_1st(declval())); - template - USTDEX_TRIVIAL_API constexpr auto query(Query _query) const - noexcept(_nothrow_queryable_with<_1st_env_t, Query>) // - -> _query_result_t<_1st_env_t, Query> - { - return _rcvr_with_env_t::_get_1st(*this).query(_query); - } - - Env _env_; -}; - -template -struct _rcvr_with_env_t -{ - using _env_t = _rcvr_with_env_t const&; + template + USTDEX_TRIVIAL_API constexpr auto query(Query) const noexcept(_nothrow_queryable_with<_1st_env_t, Query>) // + -> _query_result_t<_1st_env_t, Query> + { + return _env_t::_get_1st(*this); + } - USTDEX_TRIVIAL_API auto _rcvr() const noexcept -> Rcvr* - { - return _rcvr_; - } + _rcvr_with_env_t const* _rcvr_; + }; - template - USTDEX_TRIVIAL_API void set_value(As&&... _as) && noexcept + USTDEX_TRIVIAL_API auto base() && noexcept -> Rcvr&& { - ustdex::set_value(_rcvr_, static_cast(_as)...); + return static_cast(*this); } - template - USTDEX_TRIVIAL_API void set_error(Error&& _error) && noexcept + USTDEX_TRIVIAL_API auto base() & noexcept -> Rcvr& { - ustdex::set_error(_rcvr_, static_cast(_error)); + return *this; } - USTDEX_TRIVIAL_API void set_stopped() && noexcept + USTDEX_TRIVIAL_API auto base() const& noexcept -> Rcvr const& { - ustdex::set_stopped(_rcvr_); + return *this; } USTDEX_TRIVIAL_API auto get_env() const noexcept -> _env_t { - return _env_t{*this}; - } - - template - USTDEX_TRIVIAL_API constexpr decltype(auto) _get_1st(Query) const noexcept - { - if constexpr (_queryable_with) - { - return (_env_); - } - else if constexpr (_queryable_with, Query>) - { - return ustdex::get_env(_rcvr_); - } - } - - template - using _1st_env_t = decltype(declval()._get_1st(Query{})); - - template - USTDEX_TRIVIAL_API constexpr auto query(Query _query) const - noexcept(_nothrow_queryable_with<_1st_env_t, Query>) // - -> _query_result_t<_1st_env_t, Query> - { - return _get_1st(_query).query(_query); + return _env_t{this}; } - Rcvr* _rcvr_; Env _env_; }; diff --git a/include/ustdex/detail/receiver_with_env.hpp b/include/ustdex/detail/receiver_with_env.hpp deleted file mode 100644 index d33badc..0000000 --- a/include/ustdex/detail/receiver_with_env.hpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License Version 2.0 with LLVM Exceptions - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * https://llvm.org/LICENSE.txt - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include "cpos.hpp" -#include "env.hpp" - -// Must be the last include -#include "prologue.hpp" - -namespace ustdex -{ -template -struct _receiver_with_env_t : Rcvr -{ - using _env_t = _receiver_with_env_t const&; - - USTDEX_TRIVIAL_API auto rcvr() noexcept -> Rcvr& - { - return *this; - } - - USTDEX_TRIVIAL_API auto rcvr() const noexcept -> const Rcvr& - { - return *this; - } - - USTDEX_TRIVIAL_API auto get_env() const noexcept -> _env_t - { - return _env_t{*this}; - } - - template - USTDEX_TRIVIAL_API constexpr decltype(auto) _get_1st(Query) const noexcept - { - if constexpr (_queryable) - { - return (_env); - } - else if constexpr (_queryable, Query>) - { - return ustdex::get_env(static_cast(*this)); - } - } - - template - using _1st_env_t = decltype(DECLVAL(const Self&)._get_1st(Query{})); - - template - USTDEX_TRIVIAL_API constexpr auto query(Query query) const noexcept(_nothrow_queryable<_1st_env_t, Query>) // - -> _query_result_t<_1st_env_t, Query> - { - return _get_1st(query).query(query); - } - - Env _env; -}; - -template -struct _receiver_with_env_t -{ - using _env_t = _receiver_with_env_t const&; - - USTDEX_TRIVIAL_API auto rcvr() const noexcept -> Rcvr* - { - return _rcvr; - } - - template - USTDEX_TRIVIAL_API void set_value(As&&... as) && noexcept - { - ustdex::set_value(_rcvr, static_cast(as)...); - } - - template - USTDEX_TRIVIAL_API void set_error(Error&& error) && noexcept - { - ustdex::set_error(_rcvr, static_cast(error)); - } - - USTDEX_TRIVIAL_API void set_stopped() && noexcept - { - ustdex::set_stopped(_rcvr); - } - - USTDEX_TRIVIAL_API auto get_env() const noexcept -> _env_t - { - return _env_t{*this}; - } - - template - USTDEX_TRIVIAL_API constexpr decltype(auto) _get_1st(Query) const noexcept - { - if constexpr (_queryable) - { - return (_env); - } - else if constexpr (_queryable, Query>) - { - return ustdex::get_env(_rcvr); - } - } - - template - using _1st_env_t = decltype(DECLVAL(const Self&)._get_1st(Query{})); - - template - USTDEX_TRIVIAL_API constexpr auto query(Query query) const noexcept(_nothrow_queryable<_1st_env_t, Query>) // - -> _query_result_t<_1st_env_t, Query> - { - return _get_1st(query).query(query); - } - - Rcvr* _rcvr; - Env _env; -}; -} // namespace ustdex - -#include "epilogue.hpp" diff --git a/include/ustdex/detail/starts_on.hpp b/include/ustdex/detail/starts_on.hpp index 9f1e66a..90be5fb 100644 --- a/include/ustdex/detail/starts_on.hpp +++ b/include/ustdex/detail/starts_on.hpp @@ -43,15 +43,16 @@ inline constexpr struct start_on_t { private: template - struct USTDEX_TYPE_VISIBILITY_DEFAULT _opstate_t + struct USTDEX_TYPE_VISIBILITY_DEFAULT _opstate_t : _rcvr_with_env_t> { using operation_state_concept = operation_state_t; using _env_t = env_of_t; + using _rcvr_with_sch_t = _rcvr_with_env_t>; USTDEX_API _opstate_t(Sch _sch, Rcvr _rcvr, CvSndr&& _sndr) - : _env_rcvr_{static_cast(_rcvr), {_sch}} - , _opstate1_{connect(schedule(_env_rcvr_._env_._sch_), _rcvr_ref{*this})} - , _opstate2_{connect(static_cast(_sndr), _rcvr_ref{_env_rcvr_})} + : _rcvr_with_sch_t{static_cast(_rcvr), {_sch}} + , _opstate1_{connect(schedule(this->_env_._sch_), _rcvr_ref{*this})} + , _opstate2_{connect(static_cast(_sndr), _rcvr_ref{static_cast<_rcvr_with_sch_t&>(*this)})} {} USTDEX_IMMOVABLE(_opstate_t); @@ -66,23 +67,11 @@ inline constexpr struct start_on_t ustdex::start(_opstate2_); } - template - USTDEX_API void set_error(Error&& _error) noexcept - { - ustdex::set_error(static_cast(_env_rcvr_._rcvr()), static_cast(_error)); - } - - USTDEX_API void set_stopped() noexcept - { - ustdex::set_stopped(static_cast(_env_rcvr_._rcvr())); - } - USTDEX_API auto get_env() const noexcept -> _env_t { - return ustdex::get_env(_env_rcvr_._rcvr()); + return ustdex::get_env(this->base()); } - _rcvr_with_env_t> _env_rcvr_; connect_result_t, _rcvr_ref<_opstate_t, _env_t>> _opstate1_; connect_result_t>>> _opstate2_; }; From 3818e2474a758a72b88a2ac0369fd289db500448 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Wed, 26 Mar 2025 10:32:09 -0700 Subject: [PATCH 2/2] attempt to avoid msvc brain damage --- include/ustdex/detail/starts_on.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ustdex/detail/starts_on.hpp b/include/ustdex/detail/starts_on.hpp index 90be5fb..ac7f0e4 100644 --- a/include/ustdex/detail/starts_on.hpp +++ b/include/ustdex/detail/starts_on.hpp @@ -51,8 +51,8 @@ inline constexpr struct start_on_t USTDEX_API _opstate_t(Sch _sch, Rcvr _rcvr, CvSndr&& _sndr) : _rcvr_with_sch_t{static_cast(_rcvr), {_sch}} - , _opstate1_{connect(schedule(this->_env_._sch_), _rcvr_ref{*this})} - , _opstate2_{connect(static_cast(_sndr), _rcvr_ref{static_cast<_rcvr_with_sch_t&>(*this)})} + , _opstate1_{connect(schedule(this->_env_._sch_), _rcvr_ref<_opstate_t>{*this})} + , _opstate2_{connect(static_cast(_sndr), _rcvr_ref<_rcvr_with_sch_t>{*this})} {} USTDEX_IMMOVABLE(_opstate_t); @@ -72,8 +72,8 @@ inline constexpr struct start_on_t return ustdex::get_env(this->base()); } - connect_result_t, _rcvr_ref<_opstate_t, _env_t>> _opstate1_; - connect_result_t>>> _opstate2_; + connect_result_t, _rcvr_ref<_opstate_t, _env_t>> _opstate1_; + connect_result_t> _opstate2_; }; template