15 Different Ways to Filter Containers in Modern C++ -- Bartłomiej Filipek
Filtering items from a container is a common situation. Bartłomiej Filipek demonstrates various approaches from different versions of C++.
15 Different Ways to Filter Containers in Modern C++
by Bartłomiej Filipek
From the article:
Do you know how many ways we can implement a filter function in C++? While the problem is relatively easy to understand – take a container, copy elements that match a predicate and the return a new container – it’s good to exercise with the C++ Standard Library and check a few ideas. We can also apply some modern C++ techniques, including C++23. Let’s start!
The problem statement
To be precise by a filter, I mean a function with the following interface:
auto Filter(const Container& cont, UnaryPredicate p) {}It takes a container and a predicate, and then it creates an output container with elements that satisfy the predicate. We can use it like the following:
const std::vector<std::string> vec{ "Hello", "**txt", "World", "error", "warning", "C++", "****" }; auto filtered = Filter(vec, [](auto& elem) { return !elem.starts_with('*'); }); // filtered should have "Hello", "World", // "error", "warning", "C++"Writing such a function can be a good exercise with various options and algorithms in the Standard Library. What’s more, our function hides internal things like iterators, so it’s more like a range-based version.

Value semantics is a way of structuring programs around what values mean, not where objects live, and C++ is explicitly designed to support this model. In a value-semantic design, objects are merely vehicles for communicating state, while identity, address, and physical representation are intentionally irrelevant.
In today's post, I like to touch on a controversial topic: singletons. While I think it is best to have a codebase without singletons, the real-world shows me that singletons are often part of codebases.
Conferences are never just about the talks — they’re about time, travel, tradeoffs, and the people you meet along the way. After a year of attending several C++ events across formats and cities, this post is a personal look at how different conferences balance technical depth, community, and the experience of being there.
C++20 introduced coroutines. Quasar Chunawala, our guest editor for this edition, gives an overview.