8000 Reusing generator leads to skipping value · Issue #84 · andreasbuhr/cppcoro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Reusing generator leads to skipping value #84
Open
@lungsdude

Description

@lungsdude

So I have this coroutine, which generates a sequence of numbers and store the generator in a variable to reuse it later, but when I do reuse it, it skips over first value:

cppcoro::generator<int> numbers(int start) {
    while (true) {
        co_yield start++;
    }
}

int main() {
    auto generator = numbers(0);
    for (const int& i : generator | std::views::take(5)) {
        std::cout << i << ' '; //Prints "0 1 2 3 4", which is correct
    }

    for (const int& i : generator | std::views::take(5)) {
        std::cout << i << ' '; //Prints "6 7 8 9 10", which is incorrect as it has skipped over 5 for some reason
    }
}

Here's a godbolt link to see it in action

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0