diff --git a/ChangeLog b/ChangeLog index 635e72e7..9e57e45c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ + * Coroutines are conditionally supported by the __cpp_impl_coroutine + feature test macro. There is no longer any need to define the + TROMPELOEIL_EXPERIMENTAL_COROUTINES macro in order to use coroutines + with Trompeloeil. + * Split the monolithinc "trompeloeil.hpp" into several smaller headers. You can continue to #include as usual, but you can also do more fine grained #include:s, which may diff --git a/compilation_errors/co_return_and_co_throw.cpp b/compilation_errors/co_return_and_co_throw.cpp index 980f46c7..6c924d65 100644 --- a/compilation_errors/co_return_and_co_throw.cpp +++ b/compilation_errors/co_return_and_co_throw.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: CO_THROW and CO_RETURN does not make sense -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/co_return_empty_to_non_void_coroutine.cpp b/compilation_errors/co_return_empty_to_non_void_coroutine.cpp index fcd34b44..16ab1145 100644 --- a/compilation_errors/co_return_empty_to_non_void_coroutine.cpp +++ b/compilation_errors/co_return_empty_to_non_void_coroutine.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: Expression type does not match the coroutine promise type -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/co_return_from_non_coroutine.cpp b/compilation_errors/co_return_from_non_coroutine.cpp index bd0db042..105b8263 100644 --- a/compilation_errors/co_return_from_non_coroutine.cpp +++ b/compilation_errors/co_return_from_non_coroutine.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: CO_RETURN when return type is not a coroutine -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct MS diff --git a/compilation_errors/co_return_on_forbidden_call.cpp b/compilation_errors/co_return_on_forbidden_call.cpp index 312be952..6acf5ca9 100644 --- a/compilation_errors/co_return_on_forbidden_call.cpp +++ b/compilation_errors/co_return_on_forbidden_call.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: CO_RETURN for forbidden call does not make sense -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/co_return_value_to_void_coroutine.cpp b/compilation_errors/co_return_value_to_void_coroutine.cpp index 8b8e4a12..f09c518e 100644 --- a/compilation_errors/co_return_value_to_void_coroutine.cpp +++ b/compilation_errors/co_return_value_to_void_coroutine.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: Expression type does not match the coroutine promise type -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/co_return_with_mismatching_type.cpp b/compilation_errors/co_return_with_mismatching_type.cpp index fc77c0a7..057fe252 100644 --- a/compilation_errors/co_return_with_mismatching_type.cpp +++ b/compilation_errors/co_return_with_mismatching_type.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: Expression type does not match the coroutine promise type -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/co_throw_and_co_return.cpp b/compilation_errors/co_throw_and_co_return.cpp index 6705ee2f..21fb87eb 100644 --- a/compilation_errors/co_throw_and_co_return.cpp +++ b/compilation_errors/co_throw_and_co_return.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: CO_THROW and CO_RETURN does not make sense -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/co_throw_from_non_coroutine.cpp b/compilation_errors/co_throw_from_non_coroutine.cpp index e9bcba58..7135d8c3 100644 --- a/compilation_errors/co_throw_from_non_coroutine.cpp +++ b/compilation_errors/co_throw_from_non_coroutine.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: Do not use CO_THROW from a normal function, use THROW -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct MS diff --git a/compilation_errors/co_throw_on_forbidden_call.cpp b/compilation_errors/co_throw_on_forbidden_call.cpp index 3ee2a047..59b2e8b3 100644 --- a/compilation_errors/co_throw_on_forbidden_call.cpp +++ b/compilation_errors/co_throw_on_forbidden_call.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: CO_THROW for forbidden call does not make sense -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/co_yield_from_non_coroutine.cpp b/compilation_errors/co_yield_from_non_coroutine.cpp index 2ec6eab4..746ee031 100644 --- a/compilation_errors/co_yield_from_non_coroutine.cpp +++ b/compilation_errors/co_yield_from_non_coroutine.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: CO_YIELD when return type is not a coroutine -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include diff --git a/compilation_errors/co_yield_to_promise_without_yield_value.cpp b/compilation_errors/co_yield_to_promise_without_yield_value.cpp index 2140c7f4..4eb74af0 100644 --- a/compilation_errors/co_yield_to_promise_without_yield_value.cpp +++ b/compilation_errors/co_yield_to_promise_without_yield_value.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: CO_YIELD is incompatible with the promise type -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/co_yield_void.cpp b/compilation_errors/co_yield_void.cpp index 5d121b90..645a82ab 100644 --- a/compilation_errors/co_yield_void.cpp +++ b/compilation_errors/co_yield_void.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: You cannot CO_YIELD void -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/co_yield_with_mistamching_type.cpp b/compilation_errors/co_yield_with_mistamching_type.cpp index 11065451..21c9a118 100644 --- a/compilation_errors/co_yield_with_mistamching_type.cpp +++ b/compilation_errors/co_yield_with_mistamching_type.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: CO_YIELD is incompatible with the promise type -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/missing_co_return_from_void_coroutine.cpp b/compilation_errors/missing_co_return_from_void_coroutine.cpp index 20db45b9..ae5faa83 100644 --- a/compilation_errors/missing_co_return_from_void_coroutine.cpp +++ b/compilation_errors/missing_co_return_from_void_coroutine.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: CO_RETURN missing for coroutine -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/multiple_co_return.cpp b/compilation_errors/multiple_co_return.cpp index ec34342c..692d9805 100644 --- a/compilation_errors/multiple_co_return.cpp +++ b/compilation_errors/multiple_co_return.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: Multiple CO_RETURN does not make sense -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/multiple_co_throw.cpp b/compilation_errors/multiple_co_throw.cpp index a9beea86..fdacf280 100644 --- a/compilation_errors/multiple_co_throw.cpp +++ b/compilation_errors/multiple_co_throw.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: Multiple CO_THROW does not make sense -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/return_from_coroutine.cpp b/compilation_errors/return_from_coroutine.cpp index 5a9b3bbd..86619c50 100644 --- a/compilation_errors/return_from_coroutine.cpp +++ b/compilation_errors/return_from_coroutine.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: Do not use RETURN from a coroutine, use CO_RETURN -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/compilation_errors/throw_from_coroutine.cpp b/compilation_errors/throw_from_coroutine.cpp index e58e8343..200dc3dc 100644 --- a/compilation_errors/throw_from_coroutine.cpp +++ b/compilation_errors/throw_from_coroutine.cpp @@ -14,7 +14,6 @@ // exception: macOS\|g++-10\|clang++-1[0-3]\|c++1[147] // pass: Do not use THROW from a coroutine, use CO_THROW -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include struct task diff --git a/docs/FAQ.md b/docs/FAQ.md index 64391a19..06f071b0 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -784,8 +784,9 @@ There is experimental support to handle [`co_yield`](https://en.cppreference.com/w/cpp/language/coroutines#co_yield) from member functions that return a co-routine type. -To enable the experimental support, you must `#define` `TROMPELOEIL_EXPERIMENTAL_COROUTINES` -before `#include` of a *Trompeleil* header. +Coroutines are supported if the compiler defines the +[**`__cpp_impl_coroutines`**](https://eel.is/c++draft/cpp.predefined#:__cpp_impl_coroutine) +feature test macro. See the reference manual for [**`CO_RETURN(`** *expr* **`)`**](reference.md#CO_RETURN), [**`LR_CO_RETURN(`** *expr* **`)`**](reference.md#LR_CO_RETURN), diff --git a/docs/reference.md b/docs/reference.md index 09f13ab5..4ed28017 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -811,13 +811,10 @@ coroutine promise type. This code may alter out-parameters. `#include ` -Coroutine support must be explicitly enabled by defining -**`TROMPELOEIL_EXPERIMENTAL_COROUTINES`** before including the header. +Coroutines are supported if the compiler defines the +[**`__cpp_impl_coroutines`**](https://eel.is/c++draft/cpp.predefined#:__cpp_impl_coroutine) +feature test macro. -```Cpp -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES -#include -``` **NOTE!** Be very extra careful with lifetime issues when dealing with coroutines. @@ -832,13 +829,9 @@ coroutine promise type. This code may alter out-parameters. `#include ` -Coroutine support must be explicitly enabled by defining -**`TROMPELOEIL_EXPERIMENTAL_COROUTINES`** before including the header. - -```Cpp -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES -#include -``` +Coroutines are supported if the compiler defines the +[**`__cpp_impl_coroutines`**](https://eel.is/c++draft/cpp.predefined#:__cpp_impl_coroutine) +feature test macro. **NOTE!** Be very extra careful with lifetime issues when dealing with coroutines. @@ -857,13 +850,9 @@ See also [**`LR_CO_YIELD(`** *expr* **`]`**](#LR_CO_YIELD) `#include ` -Coroutine support must be explicitly enabled by defining -**`TROMPELOEIL_EXPERIMENTAL_COROUTINES`** before including the header. - -```Cpp -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES -#include -``` +Coroutines are supported if the compiler defines the +[**`__cpp_impl_coroutines`**](https://eel.is/c++draft/cpp.predefined#:__cpp_impl_coroutine) +feature test macro. **NOTE!** Be very extra careful with lifetime issues when dealing with coroutines. @@ -1155,13 +1144,9 @@ coroutine promise type. This code may alter out-parameters. `#include ` -Coroutine support must be explicitly enabled by defining -**`TROMPELOEIL_EXPERIMENTAL_COROUTINES`** before including the header. - -```Cpp -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES -#include -``` +Coroutines are supported if the compiler defines the +[**`__cpp_impl_coroutines`**](https://eel.is/c++draft/cpp.predefined#:__cpp_impl_coroutine) +feature test macro. **NOTE!** Any named local objects named in *expr* are captured by reference so lifetime management is important. @@ -1179,13 +1164,9 @@ coroutine promise type. This code may alter out-parameters. `#include ` -Coroutine support must be explicitly enabled by defining -**`TROMPELOEIL_EXPERIMENTAL_COROUTINES`** before including the header. - -```Cpp -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES -#include -``` +Coroutines are supported if the compiler defines the +[**`__cpp_impl_coroutines`**](https://eel.is/c++draft/cpp.predefined#:__cpp_impl_coroutine) +feature test macro. **NOTE!** Any named local objects named in *expr* are captured by reference so lifetime management is important. @@ -1207,13 +1188,10 @@ See also [**`CO_YIELD(`** *expr* **`]`**](#LR_CO_YIELD) `#include ` -Coroutine support must be explicitly enabled by defining -**`TROMPELOEIL_EXPERIMENTAL_COROUTINES`** before including the header. +Coroutines are supported if the compiler defines the +[**`__cpp_impl_coroutines`**](https://eel.is/c++draft/cpp.predefined#:__cpp_impl_coroutine) +feature test macro. -```Cpp -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES -#include -``` **NOTE!** Any named local objects named in *expr* are captured by reference so lifetime management is important. diff --git a/include/trompeloeil/coro.hpp b/include/trompeloeil/coro.hpp index 89e850ba..309ec3a0 100644 --- a/include/trompeloeil/coro.hpp +++ b/include/trompeloeil/coro.hpp @@ -15,9 +15,7 @@ #define TROMPELOEIL_CORO_HPP #if defined(__cpp_impl_coroutine) -# ifdef TROMPELOEIL_EXPERIMENTAL_COROUTINES -# define TROMPELOEIL_COROUTINES_SUPPORTED 1 -# endif +# define TROMPELOEIL_COROUTINES_SUPPORTED 1 #else # error "Coroutines are not supported by this compiler" #endif diff --git a/test/test_co_mock.cpp b/test/test_co_mock.cpp index a1f088e1..ba7aed2f 100644 --- a/test/test_co_mock.cpp +++ b/test/test_co_mock.cpp @@ -13,7 +13,6 @@ #ifdef __cpp_impl_coroutine -#define TROMPELOEIL_EXPERIMENTAL_COROUTINES #include #include