Skip to content

willz/generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

generator

Provide python-style generator(yield) for C++ 11

Requirements

This library is implemented using boost::context and C++ 11's new feature variadic template. So first you should have boost::context installed and use a complier that supports c++ 11.

Examples

Read examples/simple_example.cpp first, which implements a int generator and a token generator

How to Use

First, Define a class inherits GeneratorCore, and implement a public generate() method. e.x.

class SomeInt : public GeneratorCore<int> {
public:
	void generate(<whatever params you need>) {
		yield(1);
		yield(3);
		...
	}
}

Second, Create the generator via Generator template. e.x.

for (auto i : Geneorator<SomeInt>()) {
	std::cout << i << ", ";
}

will output:    1, 3, 

How to Compile

Only the generator.h file is needed for the generator library. And using options -std=c++11 -lboost_context

About

Provide python-style generator(yield) for C++ 11

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published