shared_iterator_example3.cpp 1.0 KB

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