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
4 changes: 4 additions & 0 deletions examples/inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace ex = beman::execution;

// ----------------------------------------------------------------------------

#ifdef __cpp_rtti
namespace meta {
// The code in this namespace is a fairly basic way to print types. It can
// almost certainly be done better, in particular using reflection. However,
Expand Down Expand Up @@ -186,10 +187,12 @@ struct logger_t {

inline constexpr logger_t logger{};
} // namespace
#endif

// ----------------------------------------------------------------------------

int main() {
#ifdef __cpp_rtti
auto log = [](std::string_view name) {
return [name](std::string_view msg) { std::cout << name << " message='" << msg << "'\n"; };
};
Expand All @@ -201,4 +204,5 @@ int main() {
ex::sync_wait(logger(ex::just(0, 1, 2), log("just(0, 1, 2)")));
ex::sync_wait(logger(ex::just_error(0), log("just_error(0)")) | ex::upon_error([](auto) {}));
ex::sync_wait(logger(ex::just_stopped(), log("just_stopped()")) | ex::upon_stopped([]() {}));
#endif
}
124 changes: 0 additions & 124 deletions examples/meta.hpp

This file was deleted.

4 changes: 4 additions & 0 deletions examples/sender_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ static_assert(ex::sender<just_sender<std::pmr::string>>);
static_assert(ex::sender_in<just_sender<std::pmr::string>>);

int main() {
#ifdef __cpp_exceptions
try {
#endif
auto j = just_sender<std::pmr::string>{std::pmr::string("value")};
auto t = std::move(j) | ex::then([](const std::pmr::string& v) { return v + " then"; });
auto w = ex::when_all(std::move(t));
Expand All @@ -79,7 +81,9 @@ int main() {
} else
std::cout << "operation was cancelled\n";
std::cout << "after start\n";
#ifdef __cpp_exceptions
} catch (const std::exception& ex) {
std::cout << "ERROR: " << ex.what() << "\n";
}
#endif
}
2 changes: 2 additions & 0 deletions examples/stackoverflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int main(int ac, char*[]) {
for (int i{}; i < n; ++i) {
std::cout << "await just=" << (co_await ex::just(i)) << "\n";
}
#ifdef __cpp_exceptions
if constexpr (false)
for (int i{}; i < n; ++i) {
try {
Expand All @@ -105,6 +106,7 @@ int main(int ac, char*[]) {
std::cout << "await error=" << x << "\n";
}
}
#endif
co_await ex::just_stopped();
}(ac < 2 ? 3 : 30000));
#endif
Expand Down
4 changes: 4 additions & 0 deletions examples/stop_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ auto inactive(Token token) -> void {
} // namespace

auto main() -> int {
#ifdef __cpp_exceptions
try {
#endif

exec::stop_source source;
::std::thread act([token = source.get_token()] { active(token); });
Expand All @@ -119,7 +121,9 @@ auto main() -> int {
act.join();
inact.join();
print("done\n");
#ifdef __cpp_exceptions
} catch (const std::exception& ex) {
std::cout << "ERROR: " << ex.what() << "\n";
}
#endif
}
5 changes: 3 additions & 2 deletions include/beman/execution/detail/allocator_aware_move.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ template <typename T, typename Context>
* \internal
*/
auto allocator_aware_move(T&& obj, Context&& context) noexcept -> decltype(auto) {
try {
BEMAN_EXECUTION_TRY {
if constexpr (requires { ::beman::execution::get_allocator(::beman::execution::get_env(context)); }) {
if constexpr (decltype(::beman::execution::detail::is_product_type(obj))()) {
return obj.make_from(::beman::execution::get_allocator(::beman::execution::get_env(context)),
Expand All @@ -44,7 +44,8 @@ auto allocator_aware_move(T&& obj, Context&& context) noexcept -> decltype(auto)
} else {
return ::std::forward<T>(obj);
}
} catch (...) {
}
BEMAN_EXECUTION_CATCH(...) {
::std::terminate(); //-dk:TODO investigate if that can be avoided
}
}
Expand Down
9 changes: 9 additions & 0 deletions include/beman/execution/detail/as_except_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ namespace beman::execution::detail {
template <typename Error>
//-dk:TODO add a proper precondition
decltype(auto) as_except_ptr(Error&& error) {
#ifdef __cpp_exceptions
if constexpr (::std::same_as<::std::exception_ptr, ::std::decay_t<Error>>) {
return ::std::forward<Error>(error);
} else if constexpr (::std::same_as<::std::error_code, ::std::decay_t<Error>>) {
return ::std::make_exception_ptr(::std::system_error(error));
} else {
return ::std::make_exception_ptr(::std::forward<Error>(error));
}
#else
if constexpr (::std::same_as<::std::exception_ptr, ::std::decay_t<Error>>) {
return ::std::forward<Error>(error);
} else {
::std::terminate();
return ::std::exception_ptr();
}
#endif
}
} // namespace beman::execution::detail

Expand Down
5 changes: 3 additions & 2 deletions include/beman/execution/detail/bulk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,14 @@ struct bulk_algo_t {
auto& [policy, shape, f] = state;
constexpr bool nothrow =
::beman::execution::detail::bulk_traits<is_chunked, Fun, Shape, Args...>::is_nothrow_invocable;
try {
BEMAN_EXECUTION_TRY {
[&]() noexcept(nothrow) {
::beman::execution::detail::bulk_traits<is_chunked, Fun, Shape, Args...>::invoke(
f, shape, args...);
Tag()(::std::move(rcvr), ::std::forward<Args>(args)...);
}();
} catch (...) {
}
BEMAN_EXECUTION_CATCH(...) {
if constexpr (!nothrow) {
::beman::execution::set_error(::std::move(rcvr), ::std::current_exception());
}
Expand Down
17 changes: 14 additions & 3 deletions include/beman/execution/detail/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,22 @@
#define BEMAN_EXECUTION_WITH_DEFAULT_PARALLEL_SCHEDULER_BACKEND 1
#endif

#ifdef __cpp_exceptions
#define BEMAN_EXECUTION_TRY try
#define BEMAN_EXECUTION_CATCH(e) catch (e)
#define BEMAN_EXECUTION_THROW(...) throw __VA_ARGS__
#define BEMAN_EXECUTION_RETHROW(ep) ::std::rethrow_exception(ep)
#else
#define BEMAN_EXECUTION_TRY if constexpr (true)
#define BEMAN_EXECUTION_CATCH(e) else
#define BEMAN_EXECUTION_THROW(...) ::std::terminate()
#define BEMAN_EXECUTION_RETHROW(ep) ::std::terminate()
#endif

#define BEMAN_EXECUTION_TRY_EVAL(rcvr, expr) \
do { \
try { \
(expr); \
} catch (...) { \
BEMAN_EXECUTION_TRY { (expr); } \
BEMAN_EXECUTION_CATCH(...) { \
if constexpr (!noexcept((expr))) { \
::beman::execution::set_error(::std::move((rcvr)), ::std::current_exception()); \
} \
Expand Down
10 changes: 5 additions & 5 deletions include/beman/execution/detail/completion_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ struct variant_for_signatures<::beman::execution::completion_signatures<Sigs...>
template <typename Tag, typename... Args>
static auto store_into_variant(type& storage, Tag t, Args&&... args) noexcept {
using tuple_type = decltype(select_tuple(t, ::std::forward<Args>(args)...));
try {
storage.template emplace<tuple_type>(t, ::std::forward<Args>(args)...);
} catch (...) {
BEMAN_EXECUTION_TRY { storage.template emplace<tuple_type>(t, ::std::forward<Args>(args)...); }
BEMAN_EXECUTION_CATCH(...) {
if constexpr (!std::is_nothrow_constructible_v<tuple_type, Tag, Args&&...>) {
store_into_variant(storage, ::beman::execution::set_error_t{}, ::std::current_exception());
} else {
Expand All @@ -82,7 +81,7 @@ struct variant_for_signatures<::beman::execution::completion_signatures<Sigs...>
std::visit(
[&](auto&& tuple_data) {
using tuple_type = ::std::remove_cvref_t<decltype(tuple_data)>;
try {
BEMAN_EXECUTION_TRY {
if constexpr (std::is_same_v<tuple_type, std::monostate>) {
::beman::execution::detail::unreachable();
} else {
Expand All @@ -93,7 +92,8 @@ struct variant_for_signatures<::beman::execution::completion_signatures<Sigs...>
// Make a copy, in case the tuple is destroyed by the completion call.
tuple_type{::std::move(tuple_data)});
}
} catch (...) {
}
BEMAN_EXECUTION_CATCH(...) {
if constexpr (!std::is_nothrow_constructible_v<tuple_type, tuple_type&&>) {
::beman::execution::set_error(::std::forward<Receiver>(receiver), ::std::current_exception());
} else {
Expand Down
5 changes: 2 additions & 3 deletions include/beman/execution/detail/connect_awaitable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ auto connect_awaitable(Awaiter awaiter, Receiver receiver)
::beman::execution::detail::connect_awaitable_promise<Receiver>>;

::std::exception_ptr ep;
try {
BEMAN_EXECUTION_TRY {
if constexpr (std::same_as<void, result_type>) {
co_await ::std::move(awaiter);
co_await ::beman::execution::detail::suspend_complete(::beman::execution::set_value,
Expand All @@ -97,9 +97,8 @@ auto connect_awaitable(Awaiter awaiter, Receiver receiver)
co_await ::beman::execution::detail::suspend_complete(
::beman::execution::set_value, ::std::move(receiver), co_await ::std::move(awaiter));
}
} catch (...) {
ep = ::std::current_exception();
}
BEMAN_EXECUTION_CATCH(...) { ep = ::std::current_exception(); }
co_await ::beman::execution::detail::suspend_complete(::beman::execution::set_error, ::std::move(receiver), ep);
}
} // namespace beman::execution::detail
Expand Down
5 changes: 3 additions & 2 deletions include/beman/execution/detail/continues_on.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,12 @@ struct continues_on_t {
using result_t = ::beman::execution::detail::decayed_tuple<Tag, Args...>;
constexpr bool nothrow = (::std::is_nothrow_constructible_v<::std::decay_t<Args>, Args> && ...);

try {
BEMAN_EXECUTION_TRY {
[&]() noexcept(nothrow) {
state.async_result.template emplace<result_t>(Tag(), ::std::forward<Args>(args)...);
}();
} catch (...) {
}
BEMAN_EXECUTION_CATCH(...) {
if constexpr (!nothrow) {
state.async_result
.template emplace<::std::tuple<::beman::execution::set_error_t, ::std::exception_ptr>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ consteval auto get_completion_signatures() -> ::beman::execution::detail::valid_
::beman::execution::set_stopped_t()>{};
}
} else if constexpr (sizeof...(Env) == 0)
return (throw ::beman::execution::detail::dependent_sender_error<Sender>(),
return (BEMAN_EXECUTION_THROW(::beman::execution::detail::dependent_sender_error<Sender>()),
::beman::execution::completion_signatures<>{});
else
return (throw ::beman::execution::detail::get_completion_signatures_error<Sender, Env...>(),
return (BEMAN_EXECUTION_THROW(::beman::execution::detail::get_completion_signatures_error<Sender, Env...>()),
::beman::execution::completion_signatures<>{});
}
} // namespace beman::execution
Expand Down
5 changes: 2 additions & 3 deletions include/beman/execution/detail/let.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,8 @@ struct let_t {
template <typename Tag, typename Receiver, typename... Args>
auto operator()(auto, auto& state, Receiver& receiver, Tag, Args&&... args) const {
if constexpr (::std::same_as<Tag, Completion>) {
try {
(let_bind)(state, receiver, ::std::forward<Args>(args)...);
} catch (...) {
BEMAN_EXECUTION_TRY { (let_bind)(state, receiver, ::std::forward<Args>(args)...); }
BEMAN_EXECUTION_CATCH(...) {
if constexpr (not nothrow<Receiver, decltype(state.env), decltype(state.fun), Args...>) {
::beman::execution::set_error(::std::move(receiver), ::std::current_exception());
}
Expand Down
Loading
Loading