PageRenderTime 25ms CodeModel.GetById 17ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/test/statement/if_tests.cpp

http://hadesmem.googlecode.com/
C++ | 70 lines | 55 code | 9 blank | 6 comment | 6 complexity | d4d1b4362255a5cbc8a02db65cda7513 MD5 | raw file
 1/*=============================================================================
 2    Copyright (c) 2001-2007 Joel de Guzman
 3
 4    Distributed under the Boost Software License, Version 1.0. (See accompanying 
 5    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 6==============================================================================*/
 7#include <iostream>
 8#include <vector>
 9#include <algorithm>
10#include <boost/detail/lightweight_test.hpp>
11#include <boost/phoenix/core.hpp>
12#include <boost/phoenix/statement.hpp>
13#include <boost/phoenix/operator.hpp>
14
15int
16main()
17{
18    using boost::phoenix::arg_names::arg1;
19    using boost::phoenix::if_;
20    using boost::phoenix::ref;
21    
22    int init[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
23    std::vector<int> v(init, init+10);
24
25    std::cout << std::dec;
26    int x = 0;
27
28    for_each(v.begin(), v.end(),
29        if_(arg1 > 3 && arg1 <= 8)
30        [
31            std::cout << arg1 << ", ",
32            ref(x) += arg1
33        ]
34    );
35
36    std::cout << std::endl;
37    BOOST_TEST(x == 4+5+6+7+8);
38
39    x = 0;
40    int y = 0;
41    int z = 0;
42
43    for_each(v.begin(), v.end(),
44        if_(arg1 > 5)
45        [
46            std::cout << arg1 << " > 5\n",
47            ref(x) += arg1
48        ]
49        .else_
50        [
51            if_(arg1 == 5)
52            [
53                std::cout << arg1 << " == 5\n",
54                ref(z) += arg1
55            ]
56            .else_
57            [
58                std::cout << arg1 << " < 5\n",
59                ref(y) += arg1
60            ]
61        ]
62    );
63
64    std::cout << std::endl;
65    BOOST_TEST(x == 6+7+8+9+10);
66    BOOST_TEST(y == 1+2+3+4);
67    BOOST_TEST(z == 5);
68
69    return boost::report_errors();
70}