fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <functional>
  4. #include <iostream>
  5.  
  6. using find_ten_t = std::pair<std::reference_wrapper<const std::vector<int>>, std::vector<int>::const_iterator>;
  7.  
  8. auto find_ten = [](const std::vector<int>& v1, const std::vector<int>& v2) -> find_ten_t {
  9. auto it1 = std::find(v1.cbegin(), v1.cend(), 10);
  10. if (it1 != v1.cend()) {
  11. return std::make_pair(std::ref(v1), it1);
  12. }
  13. auto it2 = std::find(v2.cbegin(), v2.cend(), 10);
  14. return std::make_pair(std::cref(v2), it2);
  15. };
  16.  
  17. int main() {
  18. std::vector<int> v1{ 1, 2, 3 };
  19. std::vector<int> v2{ 3, 4, 10 };
  20. auto r = find_ten(v1, v2);
  21. std::cout << "r.first[0] = " << r.first.get()[0] << "\n";
  22. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
r.first[0] = 3