Search code examples
c++clionc++20c++-coroutine

Couldn't use generator and task in clion on mac


I have such code:

generator<int> range(int start, int end) {
    while (start < end) {
        co_yield start;
        start++;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    for (auto n: range(0, 10)) {
        cout << n << ' ';
    }
}

When I compile it, I get an error:

error: no template named 'generator'; did you mean 'iterator'?

I have a similar error with the task. Is it a problem with the support of c++20? How to fix?


Solution

  • As 康桓瑋 said, it is still in the proposal stage, the workaround is to use a third-party library such as cppcoro's generator implementation.