In the Smart Output Iterators library, the unzip output iterator allows to send the various elements contained in tuples or pairs to as many output collections: std::vector<std::tuple<int, int, int>> lines = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12} }; std::vector<int> column1, column2, column3; std::copy(begin(lines), end(lines), fluent::output::unzip(back_inserter(column1), back_inserter(column2), back_inserter(column3))); This […]
Applying a function to each element of a collection and outputting the results into another collection is a very common thing to do, in C++ or elsewhere. In C++, we have the std::transform algorithm to do this, a central piece of the STL algorithms library. To illustrate, consider the following program: #include <algorithm> #include <iterator> […]
Smart output iterators are output iterators that do more than just sending a piece of data from an STL algorithm to a container. They can embed logic that relieves the algorithm of some of its responsibilities. We have already seen examples of smart output iterators that apply a function or filter on a predicate. Now let’s […]
In the last post we saw the TPOIASI, or Terrible Problem Of Incrementing A Smart Iterator, that could incur a performance cost in code that uses range adaptors. Today, we’ll see how smart output iterators fare with the TPOIASI (spoiler: they have a way to avoid the problem). Now if you’re wondering what smart iterators, […]
The Terrible Problem Of Incrementing A Smart Iterator (or TPOIASI) is a difficulty that arises when implementing smart iterators. But even if you don’t implement smart iterators, you may use them in a disguised form, now or in the future. And then, the TPOIASI might impact your code in a subtle manner. Since the world […]
Today’s guest post is written by Jon Kalb. Jon’s infrequently updated blog is // info and he podcasts with Phil Nash on Cpp.chat. For onsite training he can be reached at jon@cpp.training. I’d like start by thanking Jonathan for creating and maintaining the Fluent{C++} blog, for the conversations that it spawns, and for letting me […]
Today’s guest post is the second part of a two-posts series written by Sidney Congard. Sidney is an almost graduated student and an intern at QuasarDB, a company writing it’s own database in C++17. He has been doing C++ in his free time regularly for two years. Also interested in writing on Fluent C++? Check […]
Today’s guest post is the first part of a two-posts series written by Sidney Congard. Sidney is an almost graduated student and an intern at QuasarDB, a company writing it’s own database in C++17. He has been doing C++ in his free time regularly for two years. Also interested in writing on Fluent C++? Submit […]
Today’s guest post is written by @walletfox, one of the hitchhikers in the C++ galaxy, trying to navigate its dark corners by writing articles, creating Mostly Harmless cheat sheets and observing the following rules: “Don’t panic! Always carry a cheat sheet next to the towel. So long and thanks for all the fish.”. Interested in writing on Fluent C++ too? Submit your […]
In a lot of cases, using STL algorithms in C++ code allows to make it more expressive. However, some developers reported to me they had a hard time diffusing the usage of the STL in their companies, as their co-workers weren’t always keen on putting the STL in their daily coding toolbox. There were several […]