all_odds.cpp 991 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #include <vector>
  7. #include <algorithm>
  8. #include <iostream>
  9. #include <boost/phoenix/core.hpp>
  10. #include <boost/phoenix/operator.hpp>
  11. #include <boost/phoenix/statement.hpp>
  12. int
  13. main()
  14. {
  15. using boost::phoenix::if_;
  16. using boost::phoenix::arg_names::arg1;
  17. int init[] = { 2, 10, 4, 5, 1, 6, 8, 3, 9, 7 };
  18. std::vector<int> c(init, init + 10);
  19. typedef std::vector<int>::iterator iterator;
  20. // Print all odd contents of an stl container c
  21. std::for_each(c.begin(), c.end(),
  22. if_(arg1 % 2 == 1)
  23. [
  24. std::cout << arg1 << ' '
  25. ]
  26. );
  27. std::cout << std::endl;
  28. return 0;
  29. }