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
16int n = 0;
17
18using std::cout;
19using std::endl;
20
21struct X
22{
23 X(int, int, int) { cout << "new X(int, int, int)" << endl; ++n; }
24 X() { cout << "new X" << endl; ++n; }
25 ~X() { cout << "delete X" << endl; --n; }
26};
27
28int
29main()
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(first: v.begin(), last: v.end(), f: arg1 = new_<X>());
43 for_each(first: v.begin(), last: v.end(), f: delete_(p: arg1));
44
45 for_each(first: v.begin(), last: v.end(), f: arg1 = new_<X>(a0: 1, a1: 2, a2: 3));
46 for_each(first: v.begin(), last: v.end(), f: delete_(p: arg1));
47 }
48
49 {
50 using boost::shared_ptr;
51 vector<shared_ptr<X> > v(10);
52 for_each(first: v.begin(), last: v.end(),
53 f: arg1 = boost::phoenix::construct<shared_ptr<X> >(a0: new_<X>())
54 );
55 }
56
57 BOOST_TEST(n == 0);
58 return boost::report_errors();
59}
60

source code of boost/libs/phoenix/test/object/new_delete_tests.cpp