diff --git a/shared_container_iterator.html b/shared_container_iterator.html index 487b932..1b65ca2 100644 --- a/shared_container_iterator.html +++ b/shared_container_iterator.html @@ -18,22 +18,23 @@ Defined in header boost/shared_container_iterator.hpp
-The purpose of the shared container iterator is to attach the lifetime -of a container to the lifetime of its iterators. In other words, -the container will be deleted after the last iterator is destroyed. -The shared container iterator is typically used to implement functions -that return iterators over a -range of objects that will only be needed for the lifetime of -the iterators. By returning a pair of shared iterators from a -function, the callee can ensure that the underlying container's -lifetime will be properly managed. +The purpose of the shared container iterator is to attach the lifetime +of a container to the lifetime of its iterators. In other words, the +container will not be deleted until after all its iterators are +destroyed. The shared container iterator is typically used to +implement functions that return iterators over a range of objects that +only need to exist for the lifetime of the iterators. By returning a +pair of shared iterators from a function, the callee can return a +heap-allocated range of objects whose lifetime is automatically managed.
-The shared container iterator augments an iterator into a shared -container with a reference counted pointer to the container. -Assuming no other references exist to the container, it will be -destroyed when the last shared container iterator is destroyed. -In all other ways, the shared container iterator -behaves the same as its base iterator. +The shared container iterator augments an iterator over a shared +container. It maintains a reference count on the shared +container. If only shared container iterators hold references to +the container, the container's lifetime will end when the last shared +container iterator over it is destroyed. In any case, the shared +container is guaranteed to persist beyond the lifetime of all +the iterators. In all other ways, the +shared container iterator behaves the same as its base iterator.
namespace boost { template <typename Container> - class shared_container_iterator_generator; + class shared_container_iterator; template <typename Container> - typename shared_container_iterator_generator<Container>::type + shared_container_iterator<Container> make_shared_container_iterator(typename Container::iterator base, boost::shared_ptr<Container> const& container); - std::pair< - typename shared_container_iterator_generator<Container>::type, - typename shared_container_iterator_generator<Container>::type + std::pair< + typename shared_container_iterator<Container>, + typename shared_container_iterator<Container> > make_shared_container_range(boost::shared_ptr<Container> const& container); - }
-template <typename Container> -class shared_container_iterator_generator -{ -public: - typedef iterator_adaptor<...> type; -}; +template <typename Container> class shared_container_iterator;+The class template shared_container_iterator +is the shared container iterator type. The Container template +type argument must model the +Container +concept. +
-The following example illustrates how to use the -shared_counter_iterator_generator to create an iterator that +The following example illustrates how to create an iterator that regulates the lifetime of a reference counted std::vector. -Though the original shared_ptr to the vector ceases to exist, the -shared_counter_iterators extend the lifetime of the container. +Though the original shared pointer ints ceases to exist +after set_range() returns, the +shared_counter_iterator objects maintain references to the + underlying vector and thereby extend the container's lifetime.
@@ -93,7 +89,7 @@ Though the original shared_ptr to the vector ceases to exist, the #include <iostream> #include <vector> -typedef boost::shared_container_iterator_generator< std::vector<int> >::type iterator; +typedef boost::shared_container_iterator< std::vector<int> > iterator; void set_range(iterator& i, iterator& end) { @@ -150,12 +146,9 @@ concept.Model of
-The shared container iterator adaptor (the type -shared_container_iterator_generator<...>::type) models the +The shared_container_iteratortype models the same iterator concept as the base iterator - (Container::iterator) up to -Random - Access Iterator. + (Container::iterator). Members
@@ -166,8 +159,8 @@ concept, though only operations defined for the base iterator will be valid. In addition it has the following constructor:-shared_container_iterator_generator::type(Container::iterator const& it, - boost::shared_ptr<Container> const& container) +shared_container_iterator(Container::iterator const& it, + boost::shared_ptr<Container> const& container)@@ -179,16 +172,15 @@ shared_container_iterator_generator::type(Container::iterator const& it,
template <typename Container> -typename shared_container_iterator_generator<AdaptableUnaryFunction,BaseIterator>::type +shared_container_iterator<Container> make_shared_container_iterator(Container::iterator base, boost::shared_ptr<Container> const& container)-This function provides an alternative to using the shared container -iterator type generator to create the iterator type before -construction. Using the object generator, a shared container iterator -can be created and passed to a function without explicitly specifying -its type. +This function provides an alternative to directly constructing a +shared container iterator. Using the object generator, a shared +container iterator can be created and passed to a function without +explicitly specifying its type.Example
@@ -246,16 +238,16 @@ explicitly named. The output from this example is the same as the previous.template <typename Container> std::pair< - typename shared_container_iterator_generator<Container>::type, - typename shared_container_iterator_generator<Container>::type + shared_container_iterator<Container>, + shared_container_iterator<Container> > make_shared_container_range(boost::shared_ptr<Container> const& container);-Class shared_container_iterator is meant primarily to return -via iterators a range of values that we can guarantee will be alive as +Class shared_container_iterator is meant primarily to return, +using iterators, a range of values that we can guarantee will be alive as long as the iterators are. This is a convenience -function to do just that. This function is equivalent to +function to do just that. It is equivalent tostd::make_pair(make_shared_container_iterator(container->begin(),container), @@ -265,7 +257,7 @@ std::make_pair(make_shared_container_iterator(container->begin(),container),Example
In the following example, a range of values is returned as a pair of -shared_container_iterators. +shared_container_iterator objects.@@ -280,10 +272,9 @@ In the following example, a range of values is returned as a pair of #include <vector> -typedef boost::shared_container_iterator_generator< std::vector<int> >::type - function_iterator; +typedef boost::shared_container_iterator< std::vector<int> > iterator; -std::pair<function_iterator,function_iterator> +std::pair<iterator,iterator> return_range() { boost::shared_ptr< std::vector<int> > range(new std::vector<int>()); range->push_back(0); @@ -299,7 +290,7 @@ return_range() { int main() { - function_iterator i,end; + iterator i,end; boost::tie(i,end) = return_range(); @@ -319,7 +310,7 @@ the previous two.
-Last modified: Wed Sep 4 15:52:17 EST 2002 +Last modified: Mon Aug 11 11:27:03 EST 2003© Copyright Ronald Garcia 2002. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright diff --git a/shared_iterator_example1.cpp b/shared_iterator_example1.cpp index db7b511..a6a8235 100644 --- a/shared_iterator_example1.cpp +++ b/shared_iterator_example1.cpp @@ -9,8 +9,7 @@ #include
#include -typedef boost::shared_container_iterator_generator< std::vector >::type - iterator; +typedef boost::shared_container_iterator< std::vector > iterator; void set_range(iterator& i, iterator& end) { diff --git a/shared_iterator_example3.cpp b/shared_iterator_example3.cpp index 0e4887f..9a492f8 100644 --- a/shared_iterator_example3.cpp +++ b/shared_iterator_example3.cpp @@ -11,10 +11,9 @@ #include -typedef boost::shared_container_iterator_generator< std::vector >::type - function_iterator; +typedef boost::shared_container_iterator< std::vector > iterator; -std::pair +std::pair return_range() { boost::shared_ptr< std::vector > range(new std::vector ()); range->push_back(0); @@ -30,7 +29,7 @@ return_range() { int main() { - function_iterator i,end; + iterator i,end; boost::tie(i,end) = return_range();