fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <numeric>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. template <typename T>
  10. void _print(const T& i)
  11. {
  12. cout<<i<<endl;
  13. }
  14. template <>
  15. void _print<bool>(const bool& i)
  16. {
  17. if (i == 0)
  18. cout<<"False"<<endl;
  19. else
  20. cout<<"True"<<endl;
  21. }
  22.  
  23. void _print(const vector<bool>::reference& i)
  24. {
  25. _print<bool>(i);
  26. }
  27.  
  28. class print
  29. {
  30. public:
  31.  
  32. template <typename T>
  33. void operator()(const T& val) const { _print(val); };
  34. };
  35.  
  36.  
  37. int main()
  38. {
  39. auto even = [&](int i)->bool{return (i%2==0);};
  40. srand(time(NULL));
  41. vector <int> test(3);
  42. generate(test.begin(),test.end(),[]()->int{return rand()%100;});
  43. for_each(test.begin(),test.end(),print());
  44. vector <bool> flag(3);
  45. transform(test.begin(),test.end(),flag.begin(),even);
  46. for_each(flag.begin(),flag.end(),print());
  47.  
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
90
27
20
True
False
True