Jonathan Boccara's blog

Piping To and From a Stream

Published October 18, 2019 - 0 Comments

So far, the pipes library is able to read from a collection and output to one or several collections. For example, to multiply by 2 the numbers greater than 3 from a collection inputs and output the results in the collections outputs1 and outputs2, we can write: auto const inputs = std::vector<int>{1, 2, 3, 4, 5}; auto […]

How to Merge Consecutive Elements in a C++ Collection

Published October 15, 2019 - 0 Comments

Merging identical consecutive elements in a collection is a recurring need, in C++ or elsewhere in programming. For example, we could want to aggregate a collection of hourly results into a collection of daily results: all the results of each day get aggregated into one for that day. In this case, being “identical” means being […]

Code It Yourself: Merging Consecutive Elements in a C++ Collection

Published October 11, 2019 - 0 Comments

After seeing how to extract words among spaces in C++, we are going to see another algorithm that, seen from the outside, does something very different, but has a similar implementation: merging identical consecutive elements in a collection. We will use STL algorithms to implement this, and strive for writing code as expressive as possible. You’ll […]

My Leanpub Interview

Published October 7, 2019 - 0 Comments

Leanpub is the platform I worked with to publish my first book, The Legacy Code Programmer’s Toolbox. More than just a platform, Leanpub is a company in the self-publishing business, and they do a lot of things around book publishing. One of those things is that they host a podcast called Frontmatter, where they interview […]

How to Create Your Own C++ Pipe

Published October 4, 2019 - 0 Comments
tee pipe C++

In this post we’re going to go through a simple example of pipe to add to the C++ pipes library: the tee pipe. This example serves as a tutorial to add a pipe to the library, if you’d like to add one and submit a pull request. We’re going to see: How to write a […]

Reducing the Code to Create a Pipe in the Pipes Library

Published October 1, 2019 - 0 Comments

After the various refactorings the pipes library went through, to define a pipe such as transform or filter we need to implement two classes: the pipe itself, and the class representing a pipeline starting with this pipe. It would be nicer if implementing a pipe would solely require one class. That would make the code clearer, […]

How to Check If an Inserted Object Was Already in a Map (with Expressive Code)

Published September 27, 2019 - 0 Comments

To insert a new entry into an STL set or map, or any of their multi- and unordered- equivalents, we use the insert method: std::map<int, std::string> myMap = // myMap is initialized with stuff… myMap.insert({12, “twelve”}); insert performs the action of inserting the new entry into the container, if that entry wasn’t there already. But insert doesn’t only […]

Expressive Code for State Machines in C++

Published September 24, 2019 - 0 Comments

This is a guest post from Valentin Tolmer. Valentin is a Software Engineer at Google, where he tries to improve the quality of the code around him. He was bitten by a template when he was young, and now only meta-programs. You can find some of his work on Github, in particular the ProtEnc library […]

Composite Pipes, part 2: Implementing Composite Pipes

Published September 20, 2019 - 0 Comments

After the refactoring of the pipes library we saw in the previous post, we’re in a situation where we have three concepts emulated with C++14 by the detection idiom: Range, Pipe and Pipeline. This allowed us to write operator>>= with different combinations of parameters: a Pipe and a Pipeline: add the pipe to the pipeline and return […]

Composite Pipes, part 1: Decoupling Operators From Classes

Published September 17, 2019 - 0 Comments

One of the things that one would expect C++ pipes to do, and that they couldn’t do until recently, is creating composite reusable pipes. Indeed, we could chain several pipes into a complete pipeline: input >>= pipes::filter([](int i) { return i % 2 == 0; }) >>= pipes::transform([](int i ){ return i * 2; }) >>= back_inserter(results); […]