1 /*=============================================================================
2 Copyright (c) 2001-2007 Joel de Guzman
3
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 ==============================================================================*/
7 #include <iostream>
8 #include <vector>
9 #include <algorithm>
10 #include <boost/shared_ptr.hpp>
11 #include <boost/detail/lightweight_test.hpp>
12 #include <boost/phoenix/core.hpp>
13 #include <boost/phoenix/object.hpp>
14 #include <boost/phoenix/operator.hpp>
15
16 int n = 0;
17
18 using std::cout;
19 using std::endl;
20
21 struct X
22 {
XX23 X(int, int, int) { cout << "new X(int, int, int)" << endl; ++n; }
XX24 X() { cout << "new X" << endl; ++n; }
~XX25 ~X() { cout << "delete X" << endl; --n; }
26 };
27
28 int
main()29 main()
30 {
31 using boost::phoenix::arg_names::arg1;
32 using boost::phoenix::construct;
33 using boost::phoenix::delete_;
34 using boost::phoenix::new_;
35
36 using std::for_each;
37 using std::vector;
38
39 {
40 vector<X*> v(10);
41
42 for_each(v.begin(), v.end(), arg1 = new_<X>());
43 for_each(v.begin(), v.end(), delete_(arg1));
44
45 for_each(v.begin(), v.end(), arg1 = new_<X>(1, 2, 3));
46 for_each(v.begin(), v.end(), delete_(arg1));
47 }
48
49 {
50 using boost::shared_ptr;
51 vector<shared_ptr<X> > v(10);
52 for_each(v.begin(), v.end(),
53 arg1 = boost::phoenix::construct<shared_ptr<X> >(new_<X>())
54 );
55 }
56
57 BOOST_TEST(n == 0);
58 return boost::report_errors();
59 }
60