fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. template<typename T1, typename T2 = typename T1::value_type>
  4. auto find_all(const T1& ar, T2 xr)
  5. {
  6. typedef typename T1::const_iterator const_iterator;
  7. vector<const_iterator> it;
  8. for (auto it2 = ar.cbegin(); it2 != ar.cend(); ++it2)
  9. if (*it2 == xr)
  10. it.push_back(it2);
  11. return it;
  12. }
  13. int main()
  14. {
  15. vector<int> ar={1,2,3,1,2,3,1,2,3,1,2,3};
  16. auto it=find_all(ar,1);
  17. for(auto x : it)
  18. cout<<distance(x,ar.cbegin())<<endl;
  19. return 0;
  20. }
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
0
-3
-6
-9