shared_iterator_example1.cpp 941 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "boost/shared_container_iterator.hpp"
  6. #include "boost/shared_ptr.hpp"
  7. #include <algorithm>
  8. #include <iostream>
  9. #include <vector>
  10. typedef boost::shared_container_iterator< std::vector<int> > iterator;
  11. void set_range(iterator& i, iterator& end) {
  12. boost::shared_ptr< std::vector<int> > ints(new std::vector<int>());
  13. ints->push_back(0);
  14. ints->push_back(1);
  15. ints->push_back(2);
  16. ints->push_back(3);
  17. ints->push_back(4);
  18. ints->push_back(5);
  19. i = iterator(ints->begin(),ints);
  20. end = iterator(ints->end(),ints);
  21. }
  22. int main() {
  23. iterator i,end;
  24. set_range(i,end);
  25. std::copy(i,end,std::ostream_iterator<int>(std::cout,","));
  26. std::cout.put('\n');
  27. return 0;
  28. }