Skip to content

Commit

Permalink
corrected RVO behaviour & removed move-ctors.
Browse files Browse the repository at this point in the history
Fixes 7a8f383.
  • Loading branch information
klemens-morgenstern committed Dec 4, 2024
1 parent 8cea71f commit 278a69b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 36 deletions.
10 changes: 1 addition & 9 deletions include/boost/cobalt/detail/gather.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,7 @@ struct gather_ranged_impl
std::vector<result_storage_type> result{cancel.size(), alloc};
#endif

#if !defined(BOOST_COBALT_NO_PMR)
awaitable(awaitable && rhs)
: fork::shared_state((512 + sizeof(co_awaitable_type<type>)) * std::size(rhs.aws))
, aws{std::move(rhs.aws), alloc}
, ready{rhs.ready.size(), alloc}
, cancel{rhs.cancel.size(), alloc}
{
}
#endif


awaitable(Range & aws_, std::false_type /* needs operator co_await */)
: fork::shared_state((512 + sizeof(co_awaitable_type<type>)) * std::size(aws_))
Expand Down
12 changes: 0 additions & 12 deletions include/boost/cobalt/detail/join.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,6 @@ struct join_ranged_impl
#endif
std::exception_ptr error;

#if !defined(BOOST_COBALT_NO_PMR)
awaitable(awaitable && rhs)
: fork::shared_state((512 + sizeof(co_awaitable_type<type>) + result_size) * std::size(rhs.aws))
, aws{std::move(rhs.aws), alloc}
, ready{rhs.ready.size(), alloc}
, cancel_{rhs.cancel_.size(), alloc}
, cancel{rhs.cancel.size(), alloc}
{
}
#endif


awaitable(Range & aws_, std::false_type /* needs operator co_await */)
: fork::shared_state((512 + sizeof(co_awaitable_type<type>) + result_size) * std::size(aws_))
, aws{alloc}
Expand Down
8 changes: 0 additions & 8 deletions include/boost/cobalt/detail/race.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,14 +458,6 @@ struct race_ranged_impl

bool has_result() const {return index != std::numeric_limits<std::size_t>::max(); }

#if !defined(BOOST_COBALT_NO_PMR)
awaitable(awaitable && rhs) : fork::shared_state((256 + sizeof(co_awaitable_type<type>) + sizeof(std::size_t)) * std::size(rhs.aws)), aws(rhs.aws)
{
reorder.assign(rhs.reorder.begin(), rhs.reorder.end());
if constexpr (traits::interruptible)
std::fill(working.begin(), working.end(), nullptr);
}
#endif

awaitable(Range & aws, URBG & g)
: fork::shared_state((256 + sizeof(co_awaitable_type<type>) + sizeof(std::size_t)) * std::size(aws))
Expand Down
47 changes: 40 additions & 7 deletions include/boost/cobalt/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,19 @@ auto interpret_as_result(std::tuple<Error, Arg> && args) -> system::result<Arg,
struct as_result_tag {};
struct as_tuple_tag {};

template<awaitable Aw>
template<awaitable_type Aw>
struct as_result_t
{
as_result_t(Aw && aw) : aw_(std::forward<Aw>(aw)) {}

template<typename Aw_>
requires requires (Aw_ && aw) {{std::forward<Aw_>(aw).operator co_await()} -> awaitable_type;}
as_result_t(Aw_ && aw) : aw_(std::forward<Aw_>(aw).operator co_await()) {}

template<typename Aw_>
requires requires (Aw_ && aw) {{operator co_await(std::forward<Aw_>(aw))} -> awaitable_type;}
as_result_t(Aw_ && aw) : aw_(operator co_await(std::forward<Aw_>(aw))) {}

bool await_ready() { return aw_.await_ready();}
template<typename T>
auto await_suspend(std::coroutine_handle<T> h) { return aw_.await_suspend(h);}
Expand Down Expand Up @@ -133,9 +141,17 @@ struct as_result_t
};


template<awaitable Aw>
template<awaitable_type Aw>
as_result_t(Aw &&) -> as_result_t<Aw>;

template<typename Aw_>
requires requires (Aw_ && aw) {{std::forward<Aw_>(aw).operator co_await()} -> awaitable_type;}
as_result_t(Aw_ && aw) -> as_result_t<decltype(std::forward<Aw_>(aw).operator co_await())>;

template<typename Aw_>
requires requires (Aw_ && aw) {{operator co_await(std::forward<Aw_>(aw))} -> awaitable_type;}
as_result_t(Aw_ && aw) -> as_result_t<decltype(operator co_await(std::forward<Aw_>(aw)))>;

template<awaitable_type Aw>
auto as_result(Aw && aw) -> as_result_t<Aw>
{
Expand All @@ -154,7 +170,7 @@ auto as_result(Aw && aw)
Aw aw;
auto operator co_await ()
{
return as_result(std::forward<Aw>(aw).operator co_await());
return as_result_t(std::forward<Aw>(aw));
}
};
return lazy_tuple{std::forward<Aw>(aw)};
Expand All @@ -172,7 +188,7 @@ auto as_result(Aw && aw)
Aw aw;
auto operator co_await ()
{
return as_result(operator co_await(std::forward<Aw>(aw)));
return as_result_t(std::forward<Aw>(aw));
}
};
return lazy_tuple{std::forward<Aw>(aw)};
Expand All @@ -185,6 +201,15 @@ struct as_tuple_t
{
as_tuple_t(Aw && aw) : aw_(std::forward<Aw>(aw)) {}

template<typename Aw_>
requires requires (Aw_ && aw) {{std::forward<Aw_>(aw).operator co_await()} -> awaitable_type;}
as_tuple_t(Aw_ && aw) : aw_(std::forward<Aw_>(aw).operator co_await()) {}

template<typename Aw_>
requires requires (Aw_ && aw) {{operator co_await(std::forward<Aw_>(aw))} -> awaitable_type;}
as_tuple_t(Aw_ && aw) : aw_(operator co_await(std::forward<Aw_>(aw))) {}


bool await_ready() { return aw_.await_ready();}
template<typename T>
auto await_suspend(std::coroutine_handle<T> h) { return aw_.await_suspend(h);}
Expand Down Expand Up @@ -257,9 +282,17 @@ struct as_tuple_t
};


template<awaitable Aw>
template<awaitable_type Aw>
as_tuple_t(Aw &&) -> as_tuple_t<Aw>;

template<typename Aw_>
requires requires (Aw_ && aw) {{std::forward<Aw_>(aw).operator co_await()} -> awaitable_type;}
as_tuple_t(Aw_ && aw) -> as_tuple_t<decltype(std::forward<Aw_>(aw).operator co_await())>;

template<typename Aw_>
requires requires (Aw_ && aw) {{operator co_await(std::forward<Aw_>(aw))} -> awaitable_type;}
as_tuple_t(Aw_ && aw) -> as_tuple_t<decltype(operator co_await(std::forward<Aw_>(aw)))>;


template<awaitable_type Aw>
auto as_tuple(Aw && aw) -> as_tuple_t<Aw>
Expand All @@ -279,7 +312,7 @@ auto as_tuple(Aw && aw)
Aw aw;
auto operator co_await ()
{
return as_tuple(std::forward<Aw>(aw).operator co_await());
return as_tuple_t(std::forward<Aw>(aw));
}
};
return lazy_tuple{std::forward<Aw>(aw)};
Expand All @@ -297,7 +330,7 @@ auto as_tuple(Aw && aw)
Aw aw;
auto operator co_await ()
{
return as_tuple(operator co_await(std::forward<Aw>(aw)));
return as_tuple_t(std::forward<Aw>(aw));
}
};
return lazy_tuple{std::forward<Aw>(aw)};
Expand Down

0 comments on commit 278a69b

Please sign in to comment.