Ad
Code
Diff
  • #include <vector>
    #include <iostream>
    
    template <class T, class U>
    void iterateTwoVectors(std::vector<T> A, std::vector<U> B)
    {
      for (struct {typename std::vector<T>::const_iterator a; typename std::vector<U>::const_iterator b;} s = {A.begin(), B.begin()}; s.a < A.end() && s.b < B.end(); ++s.a, ++s.b)
        std::cout << *s.a << ":" << *s.b << "\n";
    }
    • #include <vector>
    • #include <tuple>
    • #include <iostream>
    • template <class T, class U>
    • void iterateTwoVectors(std::vector<T> A, std::vector<U> B)
    • {
    • for (auto [a,b] = std::tuple{A.begin(), B.begin()}; a != A.end() && b != B.end(); a++, b++)
    • {
    • std::cout << *a << ":" << *b << "
    • ";
    • }
    • for (struct {typename std::vector<T>::const_iterator a; typename std::vector<U>::const_iterator b;} s = {A.begin(), B.begin()}; s.a < A.end() && s.b < B.end(); ++s.a, ++s.b)
    • std::cout << *s.a << ":" << *s.b << "
    • ";
    • }