1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/*=============================================================================
Phoenix V1.2.1
Copyright (c) 2001-2003 Joel de Guzman
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/detail/lightweight_test.hpp>
#define PHOENIX_LIMIT 15
#include <boost/spirit/include/phoenix1_primitives.hpp>
#include <boost/spirit/include/phoenix1_functions.hpp>
#include <boost/spirit/include/phoenix1_operators.hpp>
#include <boost/spirit/include/phoenix1_special_ops.hpp>
#include <boost/spirit/include/phoenix1_statements.hpp>
using namespace phoenix;
using namespace std;
///////////////////////////////////////////////////////////////////////////////
struct poly_print_ {
template <typename ArgT>
struct result { typedef void type; };
template <typename ArgT>
void operator()(ArgT v) const
{ cout << v; }
};
function<poly_print_> poly_print;
///////////////////////////////////////////////////////////////////////////////
int
main()
{
char c1 = '1';
int i1 = 1;
double d2_5 = 2.5;
string hello = "hello";
const char* world = " world";
///////////////////////////////////////////////////////////////////////////////
//
// Block statements
//
///////////////////////////////////////////////////////////////////////////////
(
poly_print(arg1),
poly_print(arg2),
poly_print(arg3),
poly_print(arg4),
poly_print(arg5),
poly_print("\n\n")
)
(hello, c1, world, i1, d2_5);
///////////////////////////////////////////////////////////////////////////////
//
// If-else, while, do-while, for tatements
//
///////////////////////////////////////////////////////////////////////////////
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(3);
v.push_back(4);
v.push_back(5);
v.push_back(6);
v.push_back(7);
v.push_back(8);
v.push_back(9);
v.push_back(10);
cout << dec;
//////////////////////////////////
for_each(v.begin(), v.end(),
if_(arg1 > 3 && arg1 <= 8)
[
cout << arg1 << ", "
]
);
cout << endl;
//////////////////////////////////
for_each(v.begin(), v.end(),
if_(arg1 > 5)
[
cout << arg1 << " > 5\n"
]
.else_
[
if_(arg1 == 5)
[
cout << arg1 << " == 5\n"
]
.else_
[
cout << arg1 << " < 5\n"
]
]
);
cout << endl;
vector<int> t = v;
//////////////////////////////////
for_each(v.begin(), v.end(),
(
while_(arg1--)
[
cout << arg1 << ", "
],
cout << val("\n")
)
);
v = t;
cout << endl;
//////////////////////////////////
for_each(v.begin(), v.end(),
(
do_
[
cout << arg1 << ", "
]
.while_(arg1--),
cout << val("\n")
)
);
v = t;
cout << endl;
//////////////////////////////////
int iii;
for_each(v.begin(), v.end(),
(
for_(var(iii) = 0, var(iii) < arg1, ++var(iii))
[
cout << arg1 << ", "
],
cout << val("\n")
)
);
v = t;
cout << endl;
///////////////////////////////////////////////////////////////////////////////
//
// End asserts
//
///////////////////////////////////////////////////////////////////////////////
return boost::report_errors();
}
|