Pipe is an experimental algorithm library for C++ generators. It leverages the "pipe" operator|
to compose generator operations and create functional-style pipelines. For example, here is a sum of squares from 1 to 10 using Pipe:
auto sum_of_squares = count(1) // start counting from 1
| take_n(10) // take the first 10 yielded elements
| map([](auto& i) { return i * i; }) // square them
| fold(std::plus<> { }); // fold them with std::plus
The library requires coroutines (see the Coroutines Techincal Specification) currently available in VS 2015 Update 3 with the /await
compiler option.
See this blog post for ways to compose generators and the reason pipes are the way to go.
Pipe is a header only library. Get it from this repository:
git clone https://github.com/vladris/pipe
Add the include
directory to the compiler include path. Using VS 2015 Update 3, make sure to add the /await
flag to the compiler to enable experimental coroutine support. Other compilers are not yet supported.
The library has the following public headers:
- algorithm.h providing algorithms that work on generators:
- functional.h providing a set of useful functors:
- generator.h providing functions to create generators:
- traits.h providing type traits used by the library:
Check out the unit tests under the test
directory of this project for some working sample uses. Get pintest to run them.