]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/x3/rule3.cpp
420146c0458ec1ee0a6acae781fd0f9bd9dc804a
1 /*=============================================================================
2 Copyright (c) 2001-2012 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
8 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/spirit/home/x3.hpp>
10 #include <boost/fusion/include/std_pair.hpp>
17 using boost::spirit::x3::_val
;
21 template <typename Context
>
22 void operator()(Context
const& ctx
) const
24 _val(ctx
) += _attr(ctx
);
29 struct stationary
: boost::noncopyable
31 explicit stationary(int i
) : val
{i
} {}
32 stationary
& operator=(int i
) { val
= i
; return *this; }
38 namespace check_stationary
{
40 boost::spirit::x3::rule
<class a_r
, stationary
> const a
;
41 boost::spirit::x3::rule
<class b_r
, stationary
> const b
;
43 auto const a_def
= '{' >> boost::spirit::x3::int_
>> '}';
46 BOOST_SPIRIT_DEFINE(a
, b
)
53 using spirit_test::test_attr
;
54 using spirit_test::test
;
56 using namespace boost::spirit::x3::ascii
;
57 using boost::spirit::x3::rule
;
58 using boost::spirit::x3::lit
;
59 using boost::spirit::x3::eps
;
60 using boost::spirit::x3::unused_type
;
63 { // synth attribute value-init
66 typedef rule
<class r
, std::string
> rule_type
;
68 auto rdef
= rule_type()
72 BOOST_TEST(test_attr("abcdef", +rdef
, s
));
73 BOOST_TEST(s
== "abcdef");
76 { // synth attribute value-init
79 typedef rule
<class r
, std::string
> rule_type
;
81 auto rdef
= rule_type() =
85 _val(ctx
) += _attr(ctx
);
89 BOOST_TEST(test_attr("abcdef", +rdef
, s
));
90 BOOST_TEST(s
== "abcdef");
94 auto r
= rule
<class r
, int>{} = eps
[([] (auto& ctx
) {
95 using boost::spirit::x3::_val
;
96 static_assert(std::is_same
<std::decay_t
<decltype(_val(ctx
))>, unused_type
>::value
,
97 "Attribute must not be synthesized");
99 BOOST_TEST(test("", r
));
102 { // ensure no unneded synthesization, copying and moving occured
104 BOOST_TEST(test_attr("{42}", check_stationary::b
, st
));
105 BOOST_TEST_EQ(st
.val
, 42);
108 return boost::report_errors();