Functional pipeline in C++11

c++11 pipeline

I stumbled upon this nice blog post – pipable functions in C++14. This is realy fun idea as its usage plain for anybody who is familiar with unix pipelines. So i tried to use it in C++11 (without boost) from slightly different angle to make it more real-life concept.

First sample (fun, but not so interesting):

Second sample (functional style array processing):

Simple and short implementation is under the cut…

To implement the first sample  you need only the following short number of lines (C++11 without boost):

You can see a lot of C++11 features here coupled together – perfect forwarding, &&, std::bind, auto and decltype. Using this you can even define functions inside pipeline:

For second sample we need to define some extension functions. We don’t need linq library to make things work though. Let’s do it generic way:

Processing functions here are just example and not so suitable for large amount of data – but whole concept is still viable.

Last two functions are used to create pipable functors from static methods:

As you can see the concept requires very compact implementation. If you somehow applied this in real project plz write in comments.