1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
#include <iostream>
#include <tuple>
#include <vector>
#include <boost/algorithm/string.hpp>

template<typename IT1, typename IT2, typename P>
auto compare(IT1 begin1, IT1 end1, IT2 begin2, IT2 end2, P&& predicate) {
   while (begin1 != end1 && begin2 != end2) {
      if (!predicate(*begin1, *begin2)) break;
      ++begin1; ++begin2;
   }
   return std::make_tuple(begin1, begin2);
}

int main() {
   std::vector<std::string> a = {"hello", "Hallo", "willkommen"};
   std::vector<std::string> b = {"Hello", "haLLo", "Willkommen!"};
   auto [it1, it2] = compare(a.begin(), a.end(), b.begin(), b.end(),
      [](const std::string& s1, const std::string& s2) {
	 return boost::iequals(s1, s2);
      });
   std::cout << "compare stopped at: ";
   if (it1 != a.end()) {
      std::cout << "'" << *it1 << "'";
   } else {
      std::cout << "end";
   }
   std::cout << ", ";
   if (it2 != b.end()) {
      std::cout << "'" << *it2 << "'";
   } else {
      std::cout << "end";
   }
   std::cout << std::endl;
}