]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/phoenix/test/scope/dynamic_tests.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2007 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 ==============================================================================*/
11 #include <boost/detail/lightweight_test.hpp>
12 #include <boost/phoenix/core.hpp>
13 #include <boost/phoenix/operator.hpp>
14 #include <boost/phoenix/scope/dynamic.hpp>
16 struct my_dynamic
: ::boost::phoenix::dynamic
<int, std::string
, double>
18 my_dynamic() : num(init
<0>(this)), message(init
<1>(this)), real(init
<2>(this)) {}
25 // You may also use the macro below to achieve the same as above:
27 //BOOST_PHOENIX_DYNAMIC(
30 // (std::string, message)
37 using namespace boost::phoenix
;
38 using namespace boost::phoenix::arg_names
;
42 { // First stack frame
43 dynamic_frame
<my_dynamic::self_type
> frame(clos
);
46 (clos
.real
= clos
.num
/ 56.5)();
47 (clos
.message
= "Hello " + std::string("World "))();
49 { // Second stack frame
50 dynamic_frame
<my_dynamic::self_type
> frame(clos
);
52 (clos
.message
= std::string("Abracadabra "))();
53 (clos
.real
= clos
.num
* 1e30
)();
55 { // Third stack frame
56 boost::phoenix::vector3
<int, std::string
, double> init
= {-1, "Direct Init ", 3.14};
57 dynamic_frame
<my_dynamic::self_type
> frame(clos
, init
);
59 (std::cout
<< clos
.message
<< clos
.num
<< ", " << clos
.real
<< '\n')();
60 BOOST_TEST(clos
.num() == -1);
61 BOOST_TEST(clos
.message() == "Direct Init ");
64 (std::cout
<< clos
.message
<< clos
.num
<< ", " << clos
.real
<< '\n')();
65 BOOST_TEST(clos
.num() == 987);
66 BOOST_TEST(clos
.message() == "Abracadabra ");
69 (std::cout
<< clos
.message
<< clos
.num
<< ", " << clos
.real
<< '\n')();
70 BOOST_TEST(clos
.num() == 123+456);
71 BOOST_TEST(clos
.message() == "Hello " + std::string("World "));
74 return boost::report_errors();