This post is part of the STL learning resource. Today we focus on how to fill out a range or a container with the STL. std::fill and std::uninitialized_fill std::fill takes a range and a value, and sets all elements of the range as equal to this value. vector<int> v = {1, 2, 3, 4, 5}; fill(v.begin(), v.end(), 3); […]
One thing that is cruelly lacking with std::inserter is that it can do just this: inserting. In some situations this is not enough, in particular for a map: what if an element with the same key is already there? std::inserter, since it calls std::map::insert, will not do anything at all in this case. But maybe we would […]
Smart iterators add great potential to writing expressive code with the STL in C++. And the ones that are proposed natively work particularly well with vectors and with other sequence containers such as deque, list and string. But the situation is not as good for associative containers, such as maps and sets (or their flat- non-standard counterparts). […]
Today is Pi Day!! To celebrate, we launched a challenge for the most expressive code on Fluent C++, and today is the outcome of this challenge! Thank you so much for all of you that submitted a solution. I sincerely hope that you enjoyed participating to this challenge, and learned some things in the process. And […]
When C++11 arrived, lambdas were massively used in the places where functors used before. Lambdas are more elegant, involve less typing and can do pretty much all that functor did. Pretty much. But not quite. We covered how to make code expressive by using lambdas in a dedicated post, but there are a few use […]
On Fluent C++ we had already considered passing strong types by references, and realized that this wasn’t such a simple thing to do. To understand why, I suggest you read the problem statement in this previous post before starting this one, so that we are in line. So far the series on strong types contains […]
Each year, the fourteenth of March is marked by a very special event: Pi Day! It’s called this because in American notation, the 14th of March is 3/14. And during this day, the number Pi is celebrated all over the world in various ways. One notable way to celebrate it is bringing a pie to work or to university. […]
Last week I attended the Software Craftmanship Meetup in Paris and, like every time, everyone went away inspired by the ideas that were shared during the evening. This time the debate was about the methods to get better as a software developer. And since the 50 of us vehemently expressed their satisfaction about the enriching evening, I thought […]
In this episode of the STL learning resource, we see algorithms that can be used in a variety of contexts but that have one thing in common: they return a boolean characteristic of one or several ranges. The *_of series The STL provides 3 algorithms that indicates whether all, some, or none of the elements of a range satisfy […]
This post is a new one in the series about strong types. I didn’t intend the series to contain more than 3 posts initially, covering the topics of strong types to make interfaces clearer and more robust. But I later encountered a need, still about strongly typing interfaces and that I shall describe in the motivation […]