cppcoro icon indicating copy to clipboard operation
cppcoro copied to clipboard

Also support coroutines in std namespace

Open bmanga opened this issue 4 years ago • 2 comments

Is there a way to use the library with gcc trunk where the coroutine header is not marked experimental? Currently it complains about the library including <experimental/coroutine> while in gcc only the <coroutine> header is available. I presume it will also complain about all the references to the std::experimental namespace.

bmanga avatar Jan 19 '20 11:01 bmanga

I don't think you can use it with gcc right now without modifying the library. Luckily, it should be enough to simply replace all occurrences of std::experimental and <experimental/coroutine>.

I guess the library could be made compatible though by using something like this:

#if __has_include(<experimental/coroutine>)
#include <experimental/coroutine>
namespace stde = std::experimental;
#else
#include <coroutine>
namespace stde = std;
#endif

and then using the stde namespace to refer to all coroutine-related types throughout the library.

chausner avatar Mar 23 '20 20:03 chausner

FWIW I wanted to experiment a bit with generator and did exactly what chausner proposed over here: https://github.com/richard-vock/cppcoro (also added a conanfile)

I'm currently not using cppcoro in production, so I don't mind using my own fork for fun projects, but I can provide a PR if that's desired.

The corresponding commit is this: https://github.com/richard-vock/cppcoro/commit/8933f03ff18b6a004a3ff2a271f4f74fafb29a96

So it does uglify the include section a bit and I am not entirely sold on the stde:: naming, but I was also too lazy to come up with anything better...

Edit: AFAICT larger projects tend to actually define the namespace using a preprocessor define - not that this improves readability the slightest.

richard-vock avatar May 16 '20 11:05 richard-vock