diff --git a/shared_iterator_example1.cpp b/shared_iterator_example1.cpp new file mode 100644 index 0000000..db7b511 --- /dev/null +++ b/shared_iterator_example1.cpp @@ -0,0 +1,42 @@ +// (C) Copyright Ronald Garcia 2002. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +#include "boost/shared_container_iterator.hpp" +#include "boost/shared_ptr.hpp" +#include +#include +#include + +typedef boost::shared_container_iterator_generator< std::vector >::type + iterator; + + +void set_range(iterator& i, iterator& end) { + + boost::shared_ptr< std::vector > ints(new std::vector()); + + ints->push_back(0); + ints->push_back(1); + ints->push_back(2); + ints->push_back(3); + ints->push_back(4); + ints->push_back(5); + + i = iterator(ints->begin(),ints); + end = iterator(ints->end(),ints); +} + + +int main() { + + iterator i,end; + + set_range(i,end); + + std::copy(i,end,std::ostream_iterator(std::cout,",")); + std::cout.put('\n'); + + return 0; +} diff --git a/shared_iterator_example2.cpp b/shared_iterator_example2.cpp new file mode 100644 index 0000000..a1d16db --- /dev/null +++ b/shared_iterator_example2.cpp @@ -0,0 +1,42 @@ +// (C) Copyright Ronald Garcia 2002. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +#include "boost/shared_container_iterator.hpp" +#include "boost/shared_ptr.hpp" +#include +#include +#include +#include + + +template +void print_range_nl (Iterator begin, Iterator end) { + typedef typename std::iterator_traits::value_type val; + std::copy(begin,end,std::ostream_iterator(std::cout,",")); + std::cout.put('\n'); +} + + +int main() { + + typedef boost::shared_ptr< std::vector > ints_t; + { + ints_t ints(new std::vector()); + + ints->push_back(0); + ints->push_back(1); + ints->push_back(2); + ints->push_back(3); + ints->push_back(4); + ints->push_back(5); + + print_range_nl(boost::make_shared_container_iterator(ints->begin(),ints), + boost::make_shared_container_iterator(ints->end(),ints)); + } + + + + return 0; +} diff --git a/shared_iterator_example3.cpp b/shared_iterator_example3.cpp new file mode 100644 index 0000000..0e4887f --- /dev/null +++ b/shared_iterator_example3.cpp @@ -0,0 +1,41 @@ +// (C) Copyright Ronald Garcia 2002. Permission to copy, use, modify, sell and +// distribute this software is granted provided this copyright notice appears +// in all copies. This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. + +#include "boost/shared_container_iterator.hpp" +#include "boost/shared_ptr.hpp" +#include "boost/tuple/tuple.hpp" // for boost::tie +#include // for std::copy +#include +#include + + +typedef boost::shared_container_iterator_generator< std::vector >::type + function_iterator; + +std::pair +return_range() { + boost::shared_ptr< std::vector > range(new std::vector()); + range->push_back(0); + range->push_back(1); + range->push_back(2); + range->push_back(3); + range->push_back(4); + range->push_back(5); + return boost::make_shared_container_range(range); +} + + +int main() { + + + function_iterator i,end; + + boost::tie(i,end) = return_range(); + + std::copy(i,end,std::ostream_iterator(std::cout,",")); + std::cout.put('\n'); + + return 0; +}