PageRenderTime 21ms CodeModel.GetById 15ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/test/object/new_delete_tests.cpp

http://hadesmem.googlecode.com/
C++ | 59 lines | 43 code | 10 blank | 6 comment | 1 complexity | 8c4d35dae9424799b64c447398fc7a3c MD5 | raw file
 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(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}