lewissbaker / cppcoro

A library of C++ coroutine abstractions for the coroutines TS
MIT License
3.43k stars 472 forks source link

Also support coroutines in std namespace #138

Open bmanga opened 4 years ago

bmanga commented 4 years ago

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.

chausner commented 4 years ago

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.

richard-vock commented 4 years ago

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.