Ticket #6454: test_phoenix_if.cpp

File test_phoenix_if.cpp, 1.2 KB (added by Öyvind Strand <oyvind.strand@…>, 11 years ago)

Self-contained test case

Line 
1#define BOOST_SPIRIT_USE_PHOENIX_V3
2#include <boost/optional.hpp>
3#include <boost/variant.hpp>
4#include <boost/spirit/include/qi.hpp>
5#include <boost/spirit/include/phoenix.hpp>
6
7int main() {
8 namespace qi = boost::spirit::qi;
9 namespace phx = boost::phoenix;
10 using namespace boost::phoenix::arg_names;
11
12 typedef char* Iter;
13
14 //Doesn't compile
15 qi::rule<Iter, boost::optional<int>()> rule_a =
16 (-qi::int_)[
17 phx::if_(qi::_1)[
18 phx::nothing
19 ]
20 //Uncomment next line and it compiles
21 // , phx::nothing
22 ]
23 ;
24
25 //Doesn't compile
26 qi::rule<Iter, boost::optional< boost::variant<int, double> >() > rule_b =
27 (qi::int_ | qi::double_ | qi::eps)[
28 phx::if_(qi::_1)[
29 phx::nothing
30 ]
31 //Uncomment next line and it compiles
32 // , phx::nothing
33 ]
34 ;
35
36 //Compiles
37 qi::rule<Iter, boost::optional< boost::variant<int, double> >() > rule_c =
38 (qi::int_ | qi::double_ | qi::eps)[
39 phx::if_(phx::val(true))[
40 phx::nothing
41 ]
42 ]
43 ;
44
45 //Compiles
46 qi::rule<Iter, boost::optional<int>()> rule_d =
47 (-qi::int_)[
48 std::cout << qi::_1
49 ]
50 ;
51
52 //Compiles
53 phx::if_(arg1)[
54 phx::nothing
55 ]
56 (boost::optional<int>(5));
57
58 return 0;
59}