• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Phoenix V1.2.1
3     Copyright (c) 2001-2003 Joel de Guzman
4 
5     Use, modification and distribution is subject to the Boost Software
6     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7     http://www.boost.org/LICENSE_1_0.txt)
8 ==============================================================================*/
9 #include <vector>
10 #include <algorithm>
11 #include <iostream>
12 #include <boost/spirit/include/phoenix1_functions.hpp>
13 #include <boost/spirit/include/phoenix1_primitives.hpp>
14 
15 using namespace std;
16 using namespace phoenix;
17 
18 struct is_odd_ {
19 
20     template <typename ArgT>
21     struct result { typedef bool type; };
22 
23     template <typename ArgT>
operator ()is_odd_24     bool operator()(ArgT arg1) const
25     { return arg1 % 2 == 1; }
26 };
27 
28 function<is_odd_> is_odd;
29 
30 int
main()31 main()
32 {
33     int init[] = { 2, 10, 4, 5, 1, 6, 8, 3, 9, 7 };
34     vector<int> c(init, init + 10);
35     typedef vector<int>::iterator iterator;
36 
37     //  Find the first odd number in container c
38     iterator it = find_if(c.begin(), c.end(), is_odd(arg1));
39 
40     if (it != c.end())
41         cout << *it;    //  if found, print the result
42     return 0;
43 }
44