fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. template <typename InputIterator>
  7. static void test(InputIterator first, InputIterator last)
  8. {
  9. std::for_each(first, last, [](decltype(*first) value){ std::cout<<value<<std::endl; });
  10. }
  11.  
  12. template <typename InputIterator, typename OutputIterator>
  13. static void test1(InputIterator first, InputIterator last, OutputIterator output)
  14. {
  15. std::copy_if(first, last, output, [](decltype(*first) value){ return value > 0; });
  16. }
  17.  
  18.  
  19. int main() {
  20. // your code goes here
  21. int myarr[5] = {1,2,3,4,5};
  22.  
  23. std::vector<int> out;
  24.  
  25. auto first = std::begin(myarr);
  26. auto last = std::end(myarr);
  27.  
  28. test(&myarr[0],
  29. &myarr[5]);
  30.  
  31. std::cout<<"try"<<std::endl;
  32.  
  33. test1(first,
  34. last,
  35. std::back_inserter(out));
  36.  
  37. for (const auto &value: myarr)
  38. {
  39. std::cout<<value<<std::endl;
  40. }
  41.  
  42. std::cout<<"end"<<std::endl;
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
1
2
3
4
5
try
1
2
3
4
5
end