fn-not_fn.cpp 1008 B

123456789101112131415161718192021222324252627282930313233343536
  1. //#define CXXOMFORT_NOTICES 1
  2. #include <cxxomfort/functional.hpp>
  3. #include <cxxomfort/cstdint.hpp>
  4. #include <cxxomfort/algorithm.hpp> // copy_if
  5. #include <cxxomfort/array.hpp>
  6. #include <algorithm>
  7. #include <iterator>
  8. #include <iostream>
  9. #include <array>
  10. //#include <vector>
  11. bool mo3 (unsigned int u) { return u % 3 == 0; }
  12. int main () {
  13. using namespace std;
  14. cxxomfort::output_info(cout); cout<< endl;
  15. array<unsigned int, 10> A = {{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}};
  16. copy_if (begin(A), end(A), ostream_iterator<unsigned int>(cout, " "), mo3);
  17. cout<< endl;
  18. copy_if (begin(A), end(A), ostream_iterator<unsigned int>(cout, " ")
  19. , not1( ptr_fun(mo3)) );
  20. cout<< endl;
  21. #if 1
  22. copy_if (begin(A), end(A), ostream_iterator<unsigned int>(cout, " ")
  23. , not_fn( ref(mo3)) );
  24. cout<< endl;
  25. #endif
  26. cout<< "algorithms: "<< CXXO_COMPILER_SUPPORT_std_cxx11_algorithms<< endl;
  27. cout<< "sorted: "<< is_sorted(begin(A), end(A))<< endl;
  28. cout<< mo3(3)<< endl;
  29. cout<< !mo3(3)<< endl;
  30. cout<< not_fn(mo3)(3)<< endl;
  31. }