C++ code to work with ranges of iterators