Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/utility/shared_iterator_test.cpp @ 47

Last change on this file since 47 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.4 KB
Line 
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 <vector>
20#include <cassert>
21
22struct resource {
23  static int count;
24  resource() { ++count; }
25  resource(resource const&) { ++count; }
26  ~resource() { --count; }
27};
28int resource::count = 0;
29
30typedef std::vector<resource> resources_t;
31
32typedef boost::shared_container_iterator< resources_t > iterator;
33
34
35void 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  assert(resource::count == 6);
45}
46
47
48int main() {
49
50  assert(resource::count == 0);
51 
52  {
53    iterator i;
54    {
55      iterator end;
56      set_range(i,end);
57      assert(resource::count == 6);
58    }
59    assert(resource::count == 6);
60  }
61  assert(resource::count == 0);
62 
63  return 0;
64}
Note: See TracBrowser for help on using the repository browser.