1 | #include<boost/proto/proto.hpp>
|
---|
2 |
|
---|
3 | using namespace boost;
|
---|
4 |
|
---|
5 | typedef proto::terminal<int>::type const terminal;
|
---|
6 |
|
---|
7 | struct equation;
|
---|
8 |
|
---|
9 | struct addition:
|
---|
10 | proto::or_
|
---|
11 | <
|
---|
12 | proto::terminal<proto::_>,
|
---|
13 | proto::plus<addition, addition>
|
---|
14 | >
|
---|
15 | {};
|
---|
16 |
|
---|
17 | struct equation:
|
---|
18 | proto::or_
|
---|
19 | <
|
---|
20 | proto::equal_to<addition, addition>
|
---|
21 | >
|
---|
22 | {};
|
---|
23 |
|
---|
24 | template<class Expr>
|
---|
25 | struct extension;
|
---|
26 |
|
---|
27 | struct my_domain:
|
---|
28 | proto::domain
|
---|
29 | <
|
---|
30 | proto::pod_generator<extension>,
|
---|
31 | equation,
|
---|
32 | proto::default_domain
|
---|
33 | >
|
---|
34 | {};
|
---|
35 |
|
---|
36 | template<class Expr>
|
---|
37 | struct lhs_extension;
|
---|
38 |
|
---|
39 | struct my_lhs_domain:
|
---|
40 | proto::domain
|
---|
41 | <
|
---|
42 | proto::pod_generator<lhs_extension>,
|
---|
43 | addition,
|
---|
44 | my_domain
|
---|
45 | >
|
---|
46 | {};
|
---|
47 |
|
---|
48 | template<class Expr>
|
---|
49 | struct rhs_extension;
|
---|
50 |
|
---|
51 | struct my_rhs_domain:
|
---|
52 | proto::domain
|
---|
53 | <
|
---|
54 | proto::pod_generator<rhs_extension>,
|
---|
55 | addition,
|
---|
56 | my_domain
|
---|
57 | >
|
---|
58 | {};
|
---|
59 |
|
---|
60 |
|
---|
61 | template<class Expr>
|
---|
62 | struct extension
|
---|
63 | {
|
---|
64 | BOOST_PROTO_BASIC_EXTENDS(
|
---|
65 | Expr
|
---|
66 | , extension<Expr>
|
---|
67 | , my_domain
|
---|
68 | )
|
---|
69 |
|
---|
70 | void test() const
|
---|
71 | {}
|
---|
72 | };
|
---|
73 |
|
---|
74 | template<class Expr>
|
---|
75 | struct lhs_extension
|
---|
76 | {
|
---|
77 | BOOST_PROTO_BASIC_EXTENDS(
|
---|
78 | Expr
|
---|
79 | , lhs_extension<Expr>
|
---|
80 | , my_lhs_domain
|
---|
81 | )
|
---|
82 | };
|
---|
83 |
|
---|
84 | template<class Expr>
|
---|
85 | struct rhs_extension
|
---|
86 | {
|
---|
87 | BOOST_PROTO_BASIC_EXTENDS(
|
---|
88 | Expr
|
---|
89 | , rhs_extension<Expr>
|
---|
90 | , my_rhs_domain
|
---|
91 | )
|
---|
92 | };
|
---|
93 |
|
---|
94 | template <typename Grammar, typename Expr>
|
---|
95 | void matches(Expr const& expr)
|
---|
96 | {
|
---|
97 | std::cout << std::boolalpha
|
---|
98 | << proto::matches<Expr, Grammar>::value << "\n";
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | int main()
|
---|
103 | {
|
---|
104 | lhs_extension<terminal> const i = {};
|
---|
105 | rhs_extension<terminal> const j = {};
|
---|
106 |
|
---|
107 |
|
---|
108 | matches<equation>(i); // false
|
---|
109 | matches<equation>(j); // false
|
---|
110 | matches<equation>(i + i); // false
|
---|
111 | matches<equation>(j + j); // false
|
---|
112 | //matches<equation>(i + j); // compile error
|
---|
113 | //matches<equation>(j + i); // compile error
|
---|
114 | matches<equation>(i == j); // true
|
---|
115 | matches<equation>(i == j + j); // true
|
---|
116 | matches<equation>(i + i == j); // true
|
---|
117 | matches<equation>(i + i == j + j); // true
|
---|
118 | }
|
---|
119 |
|
---|