Last active
August 29, 2015 14:25
-
-
Save jamboree/d6c324b6cd4a11676cda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto range(int i, int e) -> co2::generator<int> | |
{ | |
using _co2_T = ::co2::coroutine_traits<co2::generator<int> >; | |
using _co2_P = ::co2::detail::promise_t<_co2_T>; | |
using _co2_C = ::co2::coroutine<_co2_P>; | |
struct _co2_K { decltype(i) i; decltype(e) e; }; | |
_co2_K _co2_k = {std::forward<decltype(i)>(i), std::forward<decltype(e)>(e),}; | |
auto _co2_a(::co2::detail::get_alloc(std::forward<decltype(i)>(i), std::forward<decltype(e)>(e), ::co2::detail::void_{})); | |
struct _co2_F : ::co2::detail::temp::default_size, _co2_K | |
{ | |
using _co2_K::i; | |
using _co2_K::e; | |
_co2_F(_co2_K&& pack) : _co2_K(std::move(pack)) {} | |
using _co2_start = std::integral_constant<unsigned, 0>; | |
::co2::detail::avoid_plain_return operator() (_co2_C& _co2_c, unsigned& _co2_next, unsigned& _co2_eh, void* _co2_tmp) | |
{ | |
auto& _co2_promise = _co2_c.promise(); | |
::co2::detail::exception_storage _co2_ex; | |
_co2_try_again: | |
try | |
{ | |
switch (_co2_next) | |
{ | |
case _co2_start::value: | |
using _co2_curr_eh = ::co2::detail::sentinel; | |
_co2_eh = _co2_curr_eh::value; | |
{ | |
if (_co2_promise.initial_suspend()) | |
{ | |
_co2_next = 1; | |
return ::co2::detail::avoid_plain_return{}; | |
} | |
case 1: | |
if (_co2_promise.cancellation_requested()) | |
{ | |
case 2: | |
::co2::detail::cancel(&_co2_promise); | |
goto _co2_finalize; | |
} | |
}; | |
{ | |
for (; i != e; ++i) | |
do { | |
using _co2_expr_t = decltype(::co2::detail::unrvref(_co2_promise.yield_value(i))); | |
using _co2_await = ::co2::detail::temp::traits<_co2_expr_t, _co2_sz::value>; | |
_co2_await::create(_co2_tmp, _co2_promise.yield_value(i)); | |
try | |
{ | |
if (!::co2::await_ready(_co2_await::get(_co2_tmp))) | |
{ | |
_co2_next = 3; | |
if (::co2::await_suspend(_co2_await::get(_co2_tmp), _co2_c), ::co2::detail::void_{}) | |
return ::co2::detail::avoid_plain_return{}; | |
} | |
} | |
catch (...) | |
{ | |
_co2_await::reset(_co2_tmp); | |
throw; | |
} | |
case 3: | |
if (_co2_promise.cancellation_requested()) | |
{ | |
case 4: | |
_co2_await::reset(_co2_tmp); | |
::co2::detail::cancel(&_co2_promise); | |
goto _co2_finalize; | |
} | |
::co2::detail::temp::auto_reset<_co2_expr_t, _co2_sz::value> _co2_reset = {_co2_tmp}; | |
(::co2::await_resume(_co2_await::get(_co2_tmp))); | |
} while (false); | |
} | |
_co2_next = ::co2::detail::sentinel::value; | |
::co2::detail::final_result(&_co2_promise); | |
_co2_finalize: | |
::co2::detail::finalizer<_co2_F, _co2_P>{this, _co2_c, _co2_promise}; | |
} | |
} | |
catch (...) | |
{ | |
_co2_next = _co2_eh; | |
_co2_ex.set(std::current_exception()); | |
if (_co2_next != ::co2::detail::sentinel::value) | |
goto _co2_try_again; | |
::co2::detail::finalizer<_co2_F, _co2_P> fin{this, _co2_c, _co2_promise}; | |
::co2::detail::set_exception(&_co2_promise, _co2_ex); | |
} | |
return ::co2::detail::avoid_plain_return{}; | |
} | |
}; | |
using _co2_FR = ::co2::detail::frame<_co2_P, _co2_F, decltype(_co2_a)>; | |
_co2_C _co2_c(_co2_FR::create(std::move(_co2_a), std::move(_co2_k))); | |
return _co2_c.promise().get_return_object(_co2_c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment