If you look at the declaration of your make_filter_iterator template, you will see that it looks like this:
template <class Predicate, class Iterator> filter_iterator<Predicate,Iterator> make_filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());
In particular, you see that the last parameter is the default parameter, and it is set to Iterator() , which means its standard change, and for some types of iterators, it behaves like an actual iterator end() , which indicates any array one after the other , i.e. indicates garbage.
Most container types require passing the actual end() iterator.
source share