Avoid multiple #if in a single function call expression

Simply giving two entire call expressions for either Boost version greatly
improves readability in my opinion.
This commit is contained in:
Julian Brost 2025-04-11 13:05:21 +02:00
parent ccfc72267f
commit d1d399f8b3

View File

@ -105,14 +105,7 @@ public:
template <typename Handler, typename Function> template <typename Handler, typename Function>
static void SpawnCoroutine(Handler& h, Function f) { static void SpawnCoroutine(Handler& h, Function f) {
auto wrapper = [f](boost::asio::yield_context yc) {
boost::asio::spawn(h,
#if BOOST_VERSION >= 108700
std::allocator_arg,
boost::context::fixedsize_stack(GetCoroutineStackSize()),
#endif // BOOST_VERSION >= 108700
[f](boost::asio::yield_context yc) {
try { try {
f(yc); f(yc);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
@ -127,13 +120,17 @@ public:
// https://github.com/boostorg/coroutine/issues/39 // https://github.com/boostorg/coroutine/issues/39
throw; throw;
} }
}, };
#if BOOST_VERSION >= 108700 #if BOOST_VERSION >= 108700
boost::asio::spawn(h,
std::allocator_arg, boost::context::fixedsize_stack(GetCoroutineStackSize()),
std::move(wrapper),
boost::asio::detached boost::asio::detached
#else // BOOST_VERSION >= 108700
boost::coroutines::attributes(GetCoroutineStackSize()) // Set a pre-defined stack size.
#endif // BOOST_VERSION >= 108700
); );
#else // BOOST_VERSION >= 108700
boost::asio::spawn(h, std::move(wrapper), boost::coroutines::attributes(GetCoroutineStackSize()));
#endif // BOOST_VERSION >= 108700
} }
static inline static inline