Skip to content

simonwagner/cpp-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#cpp-generator

Generators for C++, using ucontext to switch context

Allows you to use yield like in Python. Makes iterators in C++ a bit bearable

##Example usage

GeneratorIterable<int> create_generator()
{
   auto c = [](Generator<int>& g)->void{
      for(int i = 0; i < 10; i++)
      {
         cout << "yield\t" << i << endl;
         g.yield(move(i));
      }
      cout << "exit\t" << endl;
   };
   
   return make_generator<int>(c);
}

int test_generator_main(int argc, char* argv[])
{
   GeneratorIterable<int> g = create_generator();
   
   for(auto i : g)
   {
      cout << "iterate\t" << i << endl;
   }
   return 0;
}

About

Generators for C++, using ucontext to switch context

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published