fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <unordered_set>
  4. using namespace std;
  5.  
  6. template<typename Container>
  7. auto get_pointers(const Container& c)
  8. {
  9. vector<decltype(begin(c))> ptrvector;
  10.  
  11. for (auto iter = begin(c); iter != end(c); ++iter)
  12. ptrvector.push_back(iter);
  13.  
  14. return ptrvector;
  15. }
  16.  
  17. int main()
  18. {
  19. vector<int> testvector = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
  20. auto ptrs1 = get_pointers(testvector);
  21. for (auto p : ptrs1)
  22. cout << *p << " ";
  23.  
  24. int testarray[] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 10 };
  25. auto ptrs2 = get_pointers(testarray);
  26. for (auto p : ptrs2)
  27. cout << *p << " ";
  28.  
  29. unordered_set<int> testset = { 21, 22, 23, 24, 25, 26, 27, 28, 29, 20 };
  30. auto ptrs3 = get_pointers(testset);
  31. for (auto p : ptrs3)
  32. cout << *p << " ";
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19 10 20 29 28 27 26 25 24 23 22 21