diff options
| author | Eric Fiselier <eric@efcs.ca> | 2017-05-26 03:02:54 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2017-05-26 03:02:54 +0000 |
| commit | 997a391466504e5d40929b6e8af88a054f44ab3d (patch) | |
| tree | d04b5b9bcbcb91f606dbd3151ff32a9029903cee /libcxx/include/experimental/coroutine | |
| parent | a911cb4ec81fade856c2f4194129b1e267e8329e (diff) | |
| download | bcm5719-llvm-997a391466504e5d40929b6e8af88a054f44ab3d.tar.gz bcm5719-llvm-997a391466504e5d40929b6e8af88a054f44ab3d.zip | |
Get <experimental/coroutine> working in C++03.
Clang supports coroutines in all dialects; Therefore libc++ should too,
otherwise the Clang extension is unusable.
I'm not convinced extending support to C++03 is a feasible long term
plan, since as the library grows to offer things like generators it
will be come increasingly difficult to limit the implementation to C++03.
However for the time being supporting C++03 isn't a big deal.
llvm-svn: 303963
Diffstat (limited to 'libcxx/include/experimental/coroutine')
| -rw-r--r-- | libcxx/include/experimental/coroutine | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/libcxx/include/experimental/coroutine b/libcxx/include/experimental/coroutine index a2ac9937efb..206fde22a23 100644 --- a/libcxx/include/experimental/coroutine +++ b/libcxx/include/experimental/coroutine @@ -27,12 +27,12 @@ class coroutine_traits; template <typename Promise = void> class coroutine_handle; // 18.11.2.7 comparison operators: -bool operator==(coroutine_handle<> x, coroutine_handle<> y) noexcept; -bool operator!=(coroutine_handle<> x, coroutine_handle<> y) noexcept; -bool operator<(coroutine_handle<> x, coroutine_handle<> y) noexcept; -bool operator<=(coroutine_handle<> x, coroutine_handle<> y) noexcept; -bool operator>=(coroutine_handle<> x, coroutine_handle<> y) noexcept; -bool operator>(coroutine_handle<> x, coroutine_handle<> y) noexcept; +bool operator==(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator!=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator<(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator<=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator>=(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; +bool operator>(coroutine_handle<> x, coroutine_handle<> y) _NOEXCEPT; // 18.11.3 trivial awaitables struct suspend_never; struct suspend_always; @@ -94,22 +94,22 @@ template <> class _LIBCPP_TEMPLATE_VIS coroutine_handle<void> { public: _LIBCPP_ALWAYS_INLINE - constexpr coroutine_handle() noexcept : __handle_(nullptr) {} + _LIBCPP_CONSTEXPR coroutine_handle() _NOEXCEPT : __handle_(nullptr) {} _LIBCPP_ALWAYS_INLINE - constexpr coroutine_handle(nullptr_t) noexcept : __handle_(nullptr) {} + _LIBCPP_CONSTEXPR coroutine_handle(nullptr_t) _NOEXCEPT : __handle_(nullptr) {} _LIBCPP_ALWAYS_INLINE - coroutine_handle& operator=(nullptr_t) noexcept { + coroutine_handle& operator=(nullptr_t) _NOEXCEPT { __handle_ = nullptr; return *this; } _LIBCPP_ALWAYS_INLINE - constexpr void* address() const noexcept { return __handle_; } + _LIBCPP_CONSTEXPR void* address() const _NOEXCEPT { return __handle_; } _LIBCPP_ALWAYS_INLINE - constexpr explicit operator bool() const noexcept { return __handle_; } + _LIBCPP_CONSTEXPR explicit operator bool() const _NOEXCEPT { return __handle_; } _LIBCPP_ALWAYS_INLINE void operator()() { resume(); } @@ -139,14 +139,14 @@ public: public: _LIBCPP_ALWAYS_INLINE - static coroutine_handle from_address(void* __addr) noexcept { + static coroutine_handle from_address(void* __addr) _NOEXCEPT { coroutine_handle __tmp; __tmp.__handle_ = __addr; return __tmp; } private: - bool __is_suspended() const noexcept { + bool __is_suspended() const _NOEXCEPT { // FIXME actually implement a check for if the coro is suspended. return __handle_; } @@ -157,27 +157,27 @@ private: // 18.11.2.7 comparison operators: inline _LIBCPP_ALWAYS_INLINE -bool operator==(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { +bool operator==(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { return __x.address() == __y.address(); } inline _LIBCPP_ALWAYS_INLINE -bool operator!=(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { +bool operator!=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { return !(__x == __y); } inline _LIBCPP_ALWAYS_INLINE -bool operator<(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { +bool operator<(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { return less<void*>()(__x.address(), __y.address()); } inline _LIBCPP_ALWAYS_INLINE -bool operator>(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { +bool operator>(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { return __y < __x; } inline _LIBCPP_ALWAYS_INLINE -bool operator<=(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { +bool operator<=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { return !(__x > __y); } inline _LIBCPP_ALWAYS_INLINE -bool operator>=(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { +bool operator>=(coroutine_handle<> __x, coroutine_handle<> __y) _NOEXCEPT { return !(__x < __y); } @@ -185,11 +185,15 @@ template <typename _Promise> class _LIBCPP_TEMPLATE_VIS coroutine_handle : public coroutine_handle<> { using _Base = coroutine_handle<>; public: +#ifndef _LIBCPP_CXX03_LANG // 18.11.2.1 construct/reset using coroutine_handle<>::coroutine_handle; - +#else + _LIBCPP_ALWAYS_INLINE coroutine_handle() _NOEXCEPT : _Base() {} + _LIBCPP_ALWAYS_INLINE coroutine_handle(nullptr_t) _NOEXCEPT : _Base(nullptr) {} +#endif _LIBCPP_INLINE_VISIBILITY - coroutine_handle& operator=(nullptr_t) noexcept { + coroutine_handle& operator=(nullptr_t) _NOEXCEPT { _Base::operator=(nullptr); return *this; } @@ -197,42 +201,42 @@ public: _LIBCPP_INLINE_VISIBILITY _Promise& promise() const { return *reinterpret_cast<_Promise*>( - __builtin_coro_promise(this->__handle_, alignof(_Promise), false)); + __builtin_coro_promise(this->__handle_, __alignof(_Promise), false)); } public: _LIBCPP_ALWAYS_INLINE - static coroutine_handle from_address(void* __addr) noexcept { + static coroutine_handle from_address(void* __addr) _NOEXCEPT { coroutine_handle __tmp; __tmp.__handle_ = __addr; return __tmp; } _LIBCPP_ALWAYS_INLINE - static coroutine_handle from_promise(_Promise& __promise) noexcept { + static coroutine_handle from_promise(_Promise& __promise) _NOEXCEPT { coroutine_handle __tmp; __tmp.__handle_ = __builtin_coro_promise(_VSTD::addressof(__promise), - alignof(_Promise), true); + __alignof(_Promise), true); return __tmp; } }; struct _LIBCPP_TYPE_VIS suspend_never { _LIBCPP_ALWAYS_INLINE - bool await_ready() const noexcept { return true; } + bool await_ready() const _NOEXCEPT { return true; } _LIBCPP_ALWAYS_INLINE - void await_suspend(coroutine_handle<>) const noexcept {} + void await_suspend(coroutine_handle<>) const _NOEXCEPT {} _LIBCPP_ALWAYS_INLINE - void await_resume() const noexcept {} + void await_resume() const _NOEXCEPT {} }; struct _LIBCPP_TYPE_VIS suspend_always { _LIBCPP_ALWAYS_INLINE - bool await_ready() const noexcept { return false; } + bool await_ready() const _NOEXCEPT { return false; } _LIBCPP_ALWAYS_INLINE - void await_suspend(coroutine_handle<>) const noexcept {} + void await_suspend(coroutine_handle<>) const _NOEXCEPT {} _LIBCPP_ALWAYS_INLINE - void await_resume() const noexcept {} + void await_resume() const _NOEXCEPT {} }; _LIBCPP_END_NAMESPACE_EXPERIMENTAL_COROUTINES @@ -243,8 +247,8 @@ template <class _Tp> struct hash<_VSTD_CORO::coroutine_handle<_Tp> > { using __arg_type = _VSTD_CORO::coroutine_handle<_Tp>; _LIBCPP_INLINE_VISIBILITY - size_t operator()(__arg_type const& __v) const noexcept - {return hash<void*>{}(__v.address());} + size_t operator()(__arg_type const& __v) const _NOEXCEPT + {return hash<void*>()(__v.address());} }; _LIBCPP_END_NAMESPACE_STD |

