• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2003 The Trustees of Indiana University.
2 
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 
7 //  Shared container iterator adaptor
8 //  Author: Ronald Garcia
9 //  See http://boost.org/libs/utility/shared_container_iterator.html
10 //  for documentation.
11 
12 //
13 // shared_iterator_test.cpp - Regression tests for shared_container_iterator.
14 //
15 
16 
17 #include "boost/shared_container_iterator.hpp"
18 #include "boost/shared_ptr.hpp"
19 #include <boost/core/lightweight_test.hpp>
20 #include <vector>
21 
22 struct resource {
23   static int count;
resourceresource24   resource() { ++count; }
resourceresource25   resource(resource const&) { ++count; }
~resourceresource26   ~resource() { --count; }
27 };
28 int resource::count = 0;
29 
30 typedef std::vector<resource> resources_t;
31 
32 typedef boost::shared_container_iterator< resources_t > iterator;
33 
34 
set_range(iterator & i,iterator & end)35 void set_range(iterator& i, iterator& end)  {
36 
37   boost::shared_ptr< resources_t > objs(new resources_t());
38 
39   for (int j = 0; j != 6; ++j)
40     objs->push_back(resource());
41 
42   i = iterator(objs->begin(),objs);
43   end = iterator(objs->end(),objs);
44   BOOST_TEST_EQ(resource::count, 6);
45 }
46 
47 
main()48 int main() {
49 
50   BOOST_TEST_EQ(resource::count, 0);
51 
52   {
53     iterator i;
54     {
55       iterator end;
56       set_range(i,end);
57       BOOST_TEST_EQ(resource::count, 6);
58     }
59     BOOST_TEST_EQ(resource::count, 6);
60   }
61   BOOST_TEST_EQ(resource::count, 0);
62 
63   return boost::report_errors();
64 }
65