shared_iterator_test.cpp 1.4 KB

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