Skip to content
Merged
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
2 changes: 2 additions & 0 deletions include/exec/asio/use_sender.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ namespace experimental::execution::asio
template <::STDEXEC::receiver Receiver>
constexpr auto connect(Receiver rcvr) const & noexcept(
::STDEXEC::__nothrow_connectable<Sender const &, receiver<Receiver>>)
-> ::STDEXEC::connect_result_t<Sender const &, receiver<Receiver>>
{
return ::STDEXEC::connect(sndr_, receiver{static_cast<Receiver &&>(rcvr)});
}

template <::STDEXEC::receiver Receiver>
constexpr auto connect(Receiver rcvr) && noexcept(
::STDEXEC::__nothrow_connectable<Sender, receiver<Receiver>>)
-> ::STDEXEC::connect_result_t<Sender, receiver<Receiver>>
{
return ::STDEXEC::connect(static_cast<Sender &&>(sndr_),
receiver{static_cast<Receiver &&>(rcvr)});
Expand Down
23 changes: 16 additions & 7 deletions include/exec/create.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,23 @@ namespace experimental::execution

struct __algo;

// The part of the state that the context's receiver uses. (It is complete while
// __state's members are computed, which call the function with the context: so the
// receiver's member functions can be instantiated then.)
template <class _Receiver>
struct __state_base
{
_Receiver __rcvr_;
};

template <class _Sender, class _Receiver>
struct __state
struct __state : __state_base<_Receiver>
{
using __data_t = __decay_t<__facade::__data_of_t<_Sender>>;
using __fun_t = decltype(__data_t::__fun_);
using __args_t = decltype(__data_t::__args_);
using __rcvr_t = __facade::__receiver_t<__algo, __callback, __state, _Sender, _Receiver>;
using __data_t = __decay_t<__facade::__data_of_t<_Sender>>;
using __fun_t = decltype(__data_t::__fun_);
using __args_t = decltype(__data_t::__args_);
using __rcvr_t =
__facade::__receiver_t<__algo, __callback, __state_base<_Receiver>, _Sender, _Receiver>;
using __context_t = __context<__rcvr_t, __args_t>;

static consteval auto __walking() noexcept -> bool
Expand Down Expand Up @@ -115,7 +125,6 @@ namespace experimental::execution
}
}

_Receiver __rcvr_;
STDEXEC_IMMOVABLE_NO_UNIQUE_ADDRESS
__context_t __ctx_;
STDEXEC_IMMOVABLE_NO_UNIQUE_ADDRESS
Expand All @@ -126,7 +135,7 @@ namespace experimental::execution
private:
template <class _Data>
constexpr explicit __state(_Data&& __data, _Receiver&& __rcvr)
: __rcvr_(static_cast<_Receiver&&>(__rcvr))
: __state_base<_Receiver>{static_cast<_Receiver&&>(__rcvr)}
, __ctx_{__rcvr_t{this}, static_cast<_Data&&>(__data).__args_}
, __fun_(static_cast<_Data&&>(__data).__fun_)
{}
Expand Down
9 changes: 5 additions & 4 deletions include/exec/detail/repeat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,11 @@ namespace experimental::execution::__repeat
decltype(__algo_base::__get_state<__mconst<__ignore>::__f>(__declval<_Sender>(),
__declval<_Receiver>()));

using __iteration_effects_t = __facade::__effects<__facade::__starts<__bounce>>;

// Starts an iteration: the trampoline, which starts the body
template <class _State>
static constexpr auto __start_iteration(_State &__state) noexcept
static constexpr auto __start_iteration(_State &__state) noexcept -> __iteration_effects_t
{
using __bounce_rcvr_t = _State::__bounce_rcvr_t;
auto &__op = __state.__bounce_op_.__emplace_from(STDEXEC::connect,
Expand All @@ -269,9 +271,8 @@ namespace experimental::execution::__repeat
}
else
{
using __result_t =
__facade::__union_t<decltype(__algo_base::__start_iteration(__state)),
__facade::__effects<set_error_t(std::exception_ptr)>>;
using __eptr_effects_t = __facade::__effects<set_error_t(std::exception_ptr)>;
using __result_t = __facade::__union_t<__iteration_effects_t, __eptr_effects_t>;
STDEXEC_TRY
{
__state.__connect_body();
Expand Down
2 changes: 1 addition & 1 deletion include/exec/sequence/iterate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ namespace experimental::execution
}
}

constexpr void __start_next() noexcept final
void __start_next() noexcept final
{
STDEXEC_TRY
{
Expand Down
65 changes: 49 additions & 16 deletions include/stdexec/__detail/__manual_lifetime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import stdexec;
#else

# include "__concepts.hpp"
# include "__utility.hpp"

# if !STDEXEC_USE_MODULES()
# include <memory>
Expand Down Expand Up @@ -61,68 +62,100 @@ namespace STDEXEC
constexpr auto __construct(_Args&&... __args)
noexcept(STDEXEC::__nothrow_constructible_from<_Ty, _Args...>) -> _Ty&
{
// Use placement new instead of std::construct_at to support aggregate
// initialization with brace elision.
return *std::launder(::new (static_cast<void*>(__buffer_))
_Ty{static_cast<_Args&&>(__args)...});
STDEXEC_IF_CONSTEVAL
{
// Placement new is not usable in constant evaluation before C++26 (P2747), and
// std::construct_at uses parentheses, so brace-initialize via an emplacer.
return *std::construct_at(std::addressof(__value_),
STDEXEC::__emplace_from{
[&]() noexcept(
STDEXEC::__nothrow_constructible_from<_Ty, _Args...>)
{ return _Ty{static_cast<_Args&&>(__args)...}; }});
}
else
{
// Use placement new instead of std::construct_at to support aggregate
// initialization with brace elision.
return *::new (static_cast<void*>(std::addressof(__value_)))
_Ty{static_cast<_Args&&>(__args)...};
}
}

//! Construct the `_Ty` in place from the result of calling `func`. There
//! are no safeties guarding against the case that there's already one
//! there.
template <class _Func, class... _Args>
constexpr auto __construct_from(_Func&& func, _Args&&... __args) -> _Ty&
constexpr auto __construct_from(_Func&& func, _Args&&... __args)
noexcept(STDEXEC::__nothrow_callable<_Func, _Args...>) -> _Ty&
{
// Use placement new instead of std::construct_at in case the function
// returns an immovable type.
return *std::launder(::new (static_cast<void*>(__buffer_))
_Ty{static_cast<_Func&&>(func)(static_cast<_Args&&>(__args)...)});
STDEXEC_IF_CONSTEVAL
{
// std::construct_at would need _Ty to be movable, so convert from an emplacer,
// whose conversion function's result initializes the object directly.
return *std::construct_at(
std::addressof(__value_),
STDEXEC::__emplace_from{
[&]() noexcept(STDEXEC::__nothrow_callable<_Func, _Args...>) -> _Ty
{ return static_cast<_Func&&>(func)(static_cast<_Args&&>(__args)...); }});
}
else
{
// Use placement new instead of std::construct_at in case the function
// returns an immovable type.
return *::new (static_cast<void*>(std::addressof(__value_)))
_Ty{static_cast<_Func&&>(func)(static_cast<_Args&&>(__args)...)};
}
}

//! End the lifetime of the contained `_Ty`.
//! @pre The lifetime has started.
constexpr void __destroy() noexcept
{
std::destroy_at(&__get());
std::destroy_at(std::addressof(__value_));
}

//! Get access to the `_Ty`.
//! @pre The lifetime has started.
constexpr auto __get() & noexcept -> _Ty&
{
return *reinterpret_cast<_Ty*>(__buffer_);
return __value_;
}

//! Get access to the `_Ty`.
//! @pre The lifetime has started.
constexpr auto __get() && noexcept -> _Ty&&
{
return static_cast<_Ty&&>(*reinterpret_cast<_Ty*>(__buffer_));
return static_cast<_Ty&&>(__value_);
}

//! Get access to the `_Ty`.
//! @pre The lifetime has started.
[[nodiscard]]
constexpr auto __get() const & noexcept -> _Ty const &
{
return *reinterpret_cast<_Ty const *>(__buffer_);
return __value_;
}

[[nodiscard]]
constexpr auto __get() const && noexcept -> _Ty const && = delete;

constexpr auto operator->() noexcept -> _Ty*
{
return reinterpret_cast<_Ty*>(__buffer_);
return std::addressof(__value_);
}

constexpr auto operator->() const noexcept -> _Ty const *
{
return reinterpret_cast<_Ty const *>(__buffer_);
return std::addressof(__value_);
}

private:
alignas(_Ty) unsigned char __buffer_[sizeof(_Ty)]{};
// A union, rather than a byte buffer, so that the _Ty's lifetime can be managed
// in constant evaluation.
union
{
_Ty __value_;
};
};

template <class _Reference>
Expand Down
4 changes: 2 additions & 2 deletions include/stdexec/__detail/__optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ namespace STDEXEC

template <class _Fn, class... _Args>
requires __std::same_as<_Tp, __call_result_t<_Fn, _Args...>>
auto __emplace_from(_Fn&& __f, _Args&&... __args) noexcept(__nothrow_callable<_Fn, _Args...>)
-> _Tp&
constexpr auto __emplace_from(_Fn&& __f, _Args&&... __args)
noexcept(__nothrow_callable<_Fn, _Args...>) -> _Tp&
{
reset();
auto __sg = __mk_has_value_guard(__has_value_);
Expand Down
6 changes: 3 additions & 3 deletions include/stdexec/__detail/__parallel_scheduler_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace STDEXEC
}
}

constexpr void set_stopped() noexcept final
void set_stopped() noexcept final
{
if constexpr (_Infallible && unstoppable_token<__stop_token_t>)
{
Expand All @@ -261,7 +261,7 @@ namespace STDEXEC
}

protected:
constexpr void
void
__query_env(__type_index __query_id, __type_index __value, void* __dest) const noexcept final
{
if (__query_id == __mtypeid<get_stop_token_t>)
Expand Down Expand Up @@ -347,7 +347,7 @@ namespace STDEXEC
{
using __receiver_proxy::__receiver_proxy_base::__receiver_proxy_base;

constexpr void set_value() noexcept final
void set_value() noexcept final
{
this->__unregister_stop_callback();
STDEXEC::set_value(std::move(this->__rcvr_));
Expand Down
6 changes: 3 additions & 3 deletions include/stdexec/__detail/__schedulers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace STDEXEC
private:
template <class _Scheduler>
STDEXEC_ATTRIBUTE(host, device, always_inline)
static auto __schedule(_Scheduler &&__sched)
static constexpr auto __schedule(_Scheduler &&__sched)
noexcept(noexcept(static_cast<_Scheduler &&>(__sched).schedule()))
-> decltype(static_cast<_Scheduler &&>(__sched).schedule())
{
Expand Down Expand Up @@ -167,13 +167,13 @@ namespace STDEXEC
template <class _Scheduler>
requires __has_schedule_member<_Scheduler> && __has_scheduler_concept<__decay_t<_Scheduler>>
STDEXEC_ATTRIBUTE(host, device, always_inline)
auto operator()(_Scheduler &&__sched) const
constexpr auto operator()(_Scheduler &&__sched) const
STDEXEC_AUTO_RETURN(__schedule(static_cast<_Scheduler &&>(__sched)))

template <class _Scheduler>
requires __has_schedule_member<_Scheduler>
[[deprecated("The scheduler must define the schedule_concept tag.")]]
STDEXEC_ATTRIBUTE(host, device, always_inline) auto operator()(_Scheduler &&__sched) const
STDEXEC_ATTRIBUTE(host, device, always_inline) constexpr auto operator()(_Scheduler &&__sched) const
STDEXEC_AUTO_RETURN(__schedule(static_cast<_Scheduler &&>(__sched)))
// clang-format on
};
Expand Down
Loading
Loading