#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; } |