fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using OBJ = int;
  6.  
  7. bool foo(const OBJ& a)
  8. { return a == 1; }
  9.  
  10. int main()
  11. {
  12. std::vector< OBJ > vec = {1, 2, 3, 4};
  13. std::vector< bool > v;
  14. v.reserve(vec.size());
  15.  
  16. std::for_each(vec.begin(), vec.end(), [&v](const OBJ& a)->void
  17. {
  18. v.insert(v.end(), foo(a) ); // bool return insert at back
  19. });
  20.  
  21. for(auto const& it: v) std::cout << it << std::endl;
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 4292KB
stdin
Standard input is empty
stdout
1
0
0
0