Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/spirit/phoenix/example/fundamental/sample3.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 1.2 KB
Line 
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/phoenix/functions.hpp>
13#include <boost/spirit/phoenix/primitives.hpp>
14
15using namespace std;
16using namespace phoenix;
17
18struct is_odd_ {
19
20    template <typename ArgT>
21    struct result { typedef bool type; };
22
23    template <typename ArgT>
24    bool operator()(ArgT arg1) const
25    { return arg1 % 2 == 1; }
26};
27
28function<is_odd_> is_odd;
29
30int
31main()
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}
Note: See TracBrowser for help on using the repository browser.