==== Question ==== As you might have noticed filter is our own implementation of the function std::ranges::filter which was introduced in C++20. Discuss advantages with this approach compared to the std::remove_if + erase idiom. In particular you can focus on usability, readability or performance. ==== Answer ==== With the std::remove_if + erase idiom and given a container (like std::vector) we have to first populate the vector with values, and then remove the ones that doesn't fulfill the predicate. This is especially a problem from a performance perspective if we need to have access to all the original values afterwards. Becuase in that case we need to copy all the values first so that we don't remove them completely, meaning we have to iterate the vector *at least* twice. With our filter function we are calculating the values *lazily* meaning we only check the predicate when we actually request a new value. This has several benefits, one of them being that we do not modify the original vector at all, but instead just loops over them once and check which values fulfills the predicates and which doesn't. This means that we don't have to spend any time actually copying or removing values, which is better from a performance perspective.