Ticket #3364: testcase.cpp

File testcase.cpp, 1.9 KB (added by maurizio.vitale@…, 13 years ago)
Line 
1#include <iostream>
2#include <boost/mpl/int.hpp>
3#include <boost/proto/fusion.hpp>
4#include <boost/proto/core.hpp>
5#include <boost/proto/context.hpp>
6
7namespace mpl = boost::mpl;
8namespace proto = boost::proto;
9namespace fusion = boost::fusion;
10using proto::_;
11
12struct my_grammar : proto::or_<
13 proto::terminal< int >,
14 proto::binary_expr<_, my_grammar, my_grammar>
15 >
16{};
17
18template<typename Expr>
19struct my_expr;
20
21struct my_domain : proto::domain<proto::generator<my_expr>, my_grammar>
22{};
23
24template<typename Expr>
25struct my_expr
26 : proto::extends<Expr, my_expr<Expr>, my_domain>
27{
28 typedef proto::extends<Expr, my_expr<Expr>, my_domain> base_type;
29
30 my_expr( Expr const & expr = Expr() )
31 : base_type( expr )
32 {}
33
34 struct assign {
35 typedef int result_type;
36
37#ifdef BUG
38 template<typename T>
39 result_type operator()(const T& t, int offset) const {
40 proto::value (const_cast<T&>(t)) = offset;
41 return offset+sizeof (T);
42 }
43#else
44 template<typename T>
45 result_type operator()(T& t, int offset) {
46 proto::value (t) = offset;
47 return offset+sizeof (T);
48 }
49#endif
50
51 };
52
53 template<typename E>
54 const my_expr& operator=(const E&) const {
55 fusion::fold(proto::flatten (*this), 0, assign ());
56 return *this;
57 }
58};
59
60struct my_int
61 : my_expr< proto::terminal< int >::type >
62{
63 typedef my_expr< proto::terminal< int >::type > base_type;
64 explicit my_int (int i = 0) : base_type (base_type::proto_base_expr::make (i)) {}
65 operator int () { return proto::value (*this); }
66};
67
68int main()
69{
70 my_int i (1);
71 my_int j (2);
72 my_int k (3);
73
74 (k,j) = (j,k);
75 std::cout << j << std::endl << k << std::endl;
76 return 0;
77}
78
79
80/// Local Variables:
81/// mode:c++
82/// comment-column:60
83/// fill-column:150
84/// compile-command:"g++ -I. -I./boost -o testcase testcase.cpp"
85/// c-macro-cppflags:"-C -I. -I./boost"
86/// c-backslash-column:120
87/// c-backslash-max-column:149
88/// End: