fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4.  
  5. using Iterator=std::vector<int>::iterator;
  6. template<class Func>
  7. void foo(Iterator begin,Iterator end,Func f)
  8. {
  9. for(Iterator it=begin; it != end-1;++it)
  10. {
  11. auto f2=[&begin,&f](int& lhs,int& rhs){
  12. std::cout<<&(*begin)<<"\n"<<&lhs<<" "<<&rhs;
  13. f(lhs,rhs);
  14. };
  15.  
  16. f2(*it,*(it+1));
  17. }
  18. }
  19.  
  20. int main()
  21. {
  22. std::vector<int> a{1,5,3,4,7};
  23.  
  24. foo(a.begin(),a.end(),[](int& lhs,int& rhs){
  25. std::cout<<"\n"<<&lhs<<" "<<&rhs<<"\n\n\n";
  26. });
  27. }
  28.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
0x837a008
0x837a008  0x837a00c
0x837a008  0x837a00c


0x837a008
0x837a00c  0x837a010
0x837a00c  0x837a010


0x837a008
0x837a010  0x837a014
0x837a010  0x837a014


0x837a008
0x837a014  0x837a018
0x837a014  0x837a018