Ticket #4675: proto_test.cpp

File proto_test.cpp, 2.1 KB (added by Thomas Heller, 12 years ago)

Testcase for the ticket

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