shared_iterator_example2.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 <iterator>
  9. #include <iostream>
  10. #include <vector>
  11. template <typename Iterator>
  12. void print_range_nl (Iterator begin, Iterator end) {
  13. typedef typename std::iterator_traits<Iterator>::value_type val;
  14. std::copy(begin,end,std::ostream_iterator<val>(std::cout,","));
  15. std::cout.put('\n');
  16. }
  17. int main() {
  18. typedef boost::shared_ptr< std::vector<int> > ints_t;
  19. {
  20. ints_t ints(new std::vector<int>());
  21. ints->push_back(0);
  22. ints->push_back(1);
  23. ints->push_back(2);
  24. ints->push_back(3);
  25. ints->push_back(4);
  26. ints->push_back(5);
  27. print_range_nl(boost::make_shared_container_iterator(ints->begin(),ints),
  28. boost::make_shared_container_iterator(ints->end(),ints));
  29. }
  30. return 0;
  31. }