fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4.  
  5. using namespace std;
  6.  
  7. // dostepne od C++11
  8. template<typename InputIterator,
  9. typename OutputIterator,
  10. typename Predicate>
  11. OutputIterator copy_if(InputIterator begin,
  12. InputIterator end,
  13. OutputIterator destBegin,
  14. Predicate p)
  15. {
  16. while (begin != end) {
  17. if (p(*begin)) *destBegin++ = *begin;
  18. ++begin;
  19. }
  20. return destBegin;
  21. }
  22.  
  23. bool czyParzysta(int i)
  24. {
  25. return i%2==0;
  26. }
  27.  
  28. int main() {
  29. int tab[10]={1,2,3,4,5,6,7,8,9,10};
  30.  
  31. copy_if(tab, tab + sizeof(tab)/sizeof(tab[0]),
  32. ostream_iterator<int>(cout, "\n"),
  33. czyParzysta);
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
2
4
6
8
10