Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 18 additions & 47 deletions include/stdexec/__detail/__just.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ import stdexec;

# include "__execution_fwd.hpp"

# include "__basic_sender.hpp"
# include "__completion_behavior.hpp"
# include "__completion_signatures.hpp"
# include "__meta.hpp"
# include "__receivers.hpp"
# include "__sender_introspection.hpp"
# include "__type_traits.hpp"
# include "__sender_facade.hpp"
# include "__tuple.hpp"

# include "__prologue.hpp"

Expand All @@ -53,44 +49,19 @@ namespace STDEXEC
}
};

template <class _SetTag, class _Tuple, class _Receiver>
struct __opstate
{
constexpr void start() noexcept
{
__apply(_SetTag(), static_cast<_Tuple&&>(__data_), static_cast<_Receiver&&>(__rcvr_));
}

_Receiver __rcvr_;
_Tuple __data_;
};

template <class _JustTag>
struct __impl : __sexpr_defaults
// just(vs...), just_error(err), and just_stopped() complete inline, from start()
template <class _SetTag>
struct __algo : __facade::__defaults
{
using __set_tag_t = _JustTag::__tag_t;

static constexpr auto __get_attrs = [](__ignore, __ignore) noexcept -> __attrs<__set_tag_t>
{
return {};
};

template <class _Sender, class... _Env>
static consteval auto __get_completion_signatures()
template <class _State, class _Children>
STDEXEC_ATTRIBUTE(always_inline, host, device)
static constexpr auto __start(_State& __state, _Children&) noexcept
{
static_assert(__sender_for<_Sender, _JustTag>);
return completion_signatures<__mapply<__qf<__set_tag_t>, __decay_t<__data_of<_Sender>>>>{};
return STDEXEC::__apply(
[&]<class... _Ts>(_Ts&&... __vs) noexcept
{ return __facade::__send(__state.__rcvr_, _SetTag(), static_cast<_Ts&&>(__vs)...); },
static_cast<decltype(__state.__data_)&&>(__state.__data_));
}

static constexpr auto __connect =
[]<class _Sender, class _Receiver>(_Sender&& __sndr, _Receiver&& __rcvr) noexcept(
__nothrow_decay_copyable<_Sender>)
{
auto& [__tag, __data] = __sndr;
return __opstate<__set_tag_t, decltype(__data), _Receiver>{static_cast<_Receiver&&>(__rcvr),
STDEXEC::__forward_like<_Sender>(
__data)};
};
};
} // namespace __just

Expand Down Expand Up @@ -172,11 +143,11 @@ namespace STDEXEC
};

template <>
struct __sexpr_impl<just_t> : __just::__impl<just_t>
struct __facade::__algorithm<just_t> : __just::__algo<set_value_t>
{};

template <class... _Ts>
struct just_t::__sender : __sexpr<just_t, __tuple<_Ts...>>
struct just_t::__sender : __facade::__sender<just_t, __tuple<_Ts...>>
{};

//! @brief Construct a sender that synchronously value-completes with the
Expand Down Expand Up @@ -254,11 +225,11 @@ namespace STDEXEC
};

template <>
struct __sexpr_impl<just_error_t> : __just::__impl<just_error_t>
struct __facade::__algorithm<just_error_t> : __just::__algo<set_error_t>
{};

template <class _Error>
struct just_error_t::__sender : __sexpr<just_error_t, __tuple<_Error>>
struct just_error_t::__sender : __facade::__sender<just_error_t, __tuple<_Error>>
{};

//! @brief Construct a sender that synchronously error-completes with the
Expand Down Expand Up @@ -325,10 +296,10 @@ namespace STDEXEC
};

template <>
struct __sexpr_impl<just_stopped_t> : __just::__impl<just_stopped_t>
struct __facade::__algorithm<just_stopped_t> : __just::__algo<set_stopped_t>
{};

struct just_stopped_t::__sender : __sexpr<just_stopped_t, __tuple<>>
struct just_stopped_t::__sender : __facade::__sender<just_stopped_t, __tuple<>>
{};

//! @brief Construct a sender that synchronously stops-completes.
Expand Down
8 changes: 6 additions & 2 deletions test/stdexec/detail/test_facade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

// Tests for the sender facade in <stdexec/__detail/__sender_facade.hpp>, through algorithms
// that are written with it for the tests. None of them has hand-written completion
// signatures or hand-written completion attributes.
// that are written with it: some for the tests, and the library's own. None of them has
// hand-written completion signatures or hand-written completion attributes.

// Catch2 must come before any potential import statements
#include <catch2/catch_all.hpp>
Expand Down Expand Up @@ -357,6 +357,10 @@ namespace
static_assert(
!ex::__well_formed_sender<decltype(t_then(t_just(1), [](std::string) { return 0; }))>);

//////////////////////////////////////////////////////////////////////////////////////////
// 1. Completion signatures fall out of the code.
static_assert(has_sigs_v<decltype(ex::just(1)), ex::set_value_t(int)>);

//////////////////////////////////////////////////////////////////////////////////////////
// Run-time tests

Expand Down
Loading