Commit f5628d15 authored by Xavier Thompson's avatar Xavier Thompson

WIP Add clang compatibility

parent 854d1880
#ifndef __COROUTINE_HPP__
#define __COROUTINE_HPP__
#if defined(__clang__) && __clang__
#include <experimental/coroutine>
namespace typon
{
using std::experimental::coroutine_handle;
using std::experimental::suspend_always;
using std::experimental::suspend_never;
using std::experimental::noop_coroutine;
}
#elif defined(__GNUC__) && __GNUC__
#include <coroutine>
namespace typon
{
using std::coroutine_handle;
using std::suspend_always;
using std::suspend_never;
using std::noop_coroutine;
}
#endif
#endif // __COROUTINE_HPP__
#ifndef __TASK_HPP__
#define __TASK_HPP__
#include <coroutine>
#include <coroutine.hpp>
#include <result.hpp>
......@@ -14,7 +13,7 @@ namespace typon
{
struct promise_type;
std::coroutine_handle<promise_type> _coroutine;
coroutine_handle<promise_type> _coroutine;
~task()
{
......@@ -23,23 +22,23 @@ namespace typon
struct promise_type : result<T>
{
std::coroutine_handle<> _continuation;
coroutine_handle<> _continuation;
task get_return_object() noexcept
{
return { std::coroutine_handle<promise_type>::from_promise(*this) };
return { coroutine_handle<promise_type>::from_promise(*this) };
}
std::suspend_always initial_suspend() noexcept
suspend_always initial_suspend() noexcept
{
return {};
}
auto final_suspend() noexcept
{
struct awaitable : std::suspend_always
struct awaitable : suspend_always
{
std::coroutine_handle<> await_suspend(std::coroutine_handle<promise_type> coroutine) noexcept
coroutine_handle<> await_suspend(coroutine_handle<promise_type> coroutine) noexcept
{
return coroutine.promise()._continuation;
}
......@@ -49,18 +48,18 @@ namespace typon
}
};
auto operator co_await() const&& noexcept
auto operator co_await() && noexcept
{
struct awaitable
{
std::coroutine_handle<promise_type> _coroutine;
coroutine_handle<promise_type> _coroutine;
bool await_ready() noexcept
{
return false;
}
std::coroutine_handle<> await_suspend(std::coroutine_handle<> awaiting_coroutine) noexcept
coroutine_handle<> await_suspend(coroutine_handle<> awaiting_coroutine) noexcept
{
_coroutine.promise()._continuation = awaiting_coroutine;
return _coroutine;
......@@ -75,9 +74,9 @@ namespace typon
return awaitable { _coroutine };
}
decltype(auto) call() const&&
decltype(auto) call() &&
{
_coroutine.promise()._continuation = std::noop_coroutine();
_coroutine.promise()._continuation = noop_coroutine();
_coroutine.resume();
return _coroutine.promise().get();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment