Skip to content

Eren121/CPP20Coroutines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPP20Coroutines

Header-Only C++20 Coroutines library

This repository aims to demonstrate the capabilities of C++20 coroutines.

generator

Generates values, recursive calls are possible.

#include <iostream>
#include <generator.hpp>

// generates the first n non-negative numbers
generator<int> first_n(int n)
{
    for(int i = 0; i < n; ++i)
    {
        co_yield i;
    }
}

int main()
{
    auto gen = first_n(10);
    
    for(auto x : gen) // prints "0 1 2 3 4 5 6 7 8 9"
    {
        std::cout << x << " ";
    }
  
    std::cout << std::endl;
}

task

Generates a single value at the end with a co_return expression. A task may co_await another task.

About

Header-Only C++20 Coroutines library

Resources

License

Stars

Watchers

Forks

Packages

No packages published