find_if.cpp 922 B

12345678910111213141516171819202122232425262728
  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. int
  12. main()
  13. {
  14. using boost::phoenix::arg_names::arg1;
  15. int init[] = { 2, 10, 4, 5, 1, 6, 8, 3, 9, 7 };
  16. std::vector<int> c(init, init + 10);
  17. typedef std::vector<int>::iterator iterator;
  18. // Find the first odd number in container c
  19. iterator it = std::find_if(c.begin(), c.end(), arg1 % 2 == 1);
  20. if (it != c.end())
  21. std::cout << *it << std::endl; // if found, print the result
  22. return 0;
  23. }