/Src/Dependencies/Boost/libs/spirit/phoenix/example/users_manual/find_if.cpp

http://hadesmem.googlecode.com/ · C++ · 30 lines · 19 code · 4 blank · 7 comment · 3 complexity · 9d989968b0935f2ae29ef78f68f54bef MD5 · raw file

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