fork(2) download
  1.  
  2. #include <iostream>
  3. #include <iterator>
  4. #include <string>
  5. #include <type_traits>
  6. #include <vector>
  7.  
  8. template <typename C>
  9. using Value_Type = typename std::remove_reference<decltype(*std::begin(std::declval<C>()))>::type;
  10.  
  11. template<typename C, typename V>
  12. std::vector<Value_Type<C>*> find_all(C& cont, V v)
  13. {
  14. std::vector<Value_Type<C>*> res;
  15.  
  16. for (auto& x : cont)
  17. if (x == v)
  18. res.push_back(&x);
  19.  
  20. return res;
  21. }
  22.  
  23. int main()
  24. {
  25. std::string m{"Mary had a little lamb"};
  26. for (const auto p: find_all(m,'a'))
  27. std::cerr << *p;
  28. std::cerr << "\n";
  29. }
Success #stdin #stdout #stderr 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
aaaa