diff --git a/shared_container_iterator.html b/shared_container_iterator.html deleted file mode 100644 index ed149b5..0000000 --- a/shared_container_iterator.html +++ /dev/null @@ -1,322 +0,0 @@ - - - - - - -Shared Container Iterator Documentation - - - - -boost.png (6897 bytes) - -

Shared Container Iterator

- -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 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 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. - - -

Synopsis

- -
-namespace boost {
-  template <typename Container>
-  class shared_container_iterator;
-
-  template <typename Container>
-  shared_container_iterator<Container>
-  make_shared_container_iterator(typename Container::iterator base, 
-    boost::shared_ptr<Container> const& container);
-
-  std::pair<
-    typename shared_container_iterator<Container>,
-    typename shared_container_iterator<Container>
-  >
-  make_shared_container_range(boost::shared_ptr<Container> const& container);
-}
-
- -
- -

The Shared Container Iterator 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. - -

Example

- -

-The following example illustrates how to create an iterator that -regulates the lifetime of a reference counted std::vector. -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. -

-shared_iterator_example1.cpp: -

-#include "shared_container_iterator.hpp"
-#include "boost/shared_ptr.hpp"
-#include <algorithm>
-#include <iostream>
-#include <vector>
-
-typedef boost::shared_container_iterator< std::vector<int> > iterator;
-
-
-void set_range(iterator& i, iterator& end)  {
-
-  boost::shared_ptr< std::vector<int> > ints(new std::vector<int>());
-  
-  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<int>(std::cout,","));
-  std::cout.put('\n');
-
-  return 0;
-}
-
- -The output from this part is: -
-0,1,2,3,4,5,
-
- -

Template Parameters

- - - - - - - - - - -
ParameterDescription
ContainerThe type of the container that we wish to iterate over. It must be -a model of the -Container -concept. -
- -

Model of

- -The shared_container_iterator type models the -same iterator concept as the base iterator - (Container::iterator). - -

Members

- -The shared container iterator type implements the member functions and -operators required of the Random Access Iterator -concept, though only operations defined for the base iterator will be valid. -In addition it has the following constructor: - -
-shared_container_iterator(Container::iterator const& it,
-                          boost::shared_ptr<Container> const& container)
-
- -

-


-

- - -

The Shared Container Iterator Object Generator

- -
-template <typename Container>
-shared_container_iterator<Container>
-make_shared_container_iterator(Container::iterator base,
-                               boost::shared_ptr<Container> const& container)
-
- -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

- -This example, similar to the previous, uses -make_shared_container_iterator() to create the iterators. - -

-shared_iterator_example2.cpp: - -

-#include "shared_container_iterator.hpp"
-#include "boost/shared_ptr.hpp"
-#include <algorithm>
-#include <iterator>
-#include <iostream>
-#include <vector>
-
-
-template <typename Iterator>
-void print_range_nl (Iterator begin, Iterator end) {
-  typedef typename std::iterator_traits<Iterator>::value_type val;
-  std::copy(begin,end,std::ostream_iterator<val>(std::cout,","));
-  std::cout.put('\n');
-}
-
-
-int main() {
-
-  typedef boost::shared_ptr< std::vector<int> > ints_t;
-  {
-    ints_t ints(new std::vector<int>());
-
-    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;
-}
-
- -Observe that the shared_container_iterator type is never -explicitly named. The output from this example is the same as the previous. - -

The Shared Container Iterator Range Generator

- -
-template <typename Container>
-std::pair<
-  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, -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. It is equivalent to - -
-std::make_pair(make_shared_container_iterator(container->begin(),container),
-               make_shared_container_iterator(container->end(),container));
-
- -

Example

- -In the following example, a range of values is returned as a pair of -shared_container_iterator objects. - - -

-shared_iterator_example3.cpp: - -

-#include "shared_container_iterator.hpp"
-#include "boost/shared_ptr.hpp"
-#include "boost/tuple/tuple.hpp" // for boost::tie
-#include <algorithm>              // for std::copy
-#include <iostream>              
-#include <vector>
-
-
-typedef boost::shared_container_iterator< std::vector<int> > iterator; 
-
-std::pair<iterator,iterator>
-return_range() {
-  boost::shared_ptr< std::vector<int> > range(new std::vector<int>());
-  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() {
-
-
-  iterator i,end;
-  
-  boost::tie(i,end) = return_range();
-
-  std::copy(i,end,std::ostream_iterator<int>(std::cout,","));
-  std::cout.put('\n');
-
-  return 0;
-}
-
- -Though the range object only lives for the duration of the -return_range call, the reference counted -std::vector will live until i and end -are both destroyed. The output from this example is the same as -the previous two. - - -
- -Last modified: Mon Aug 11 11:27:03 EST 2003 - -

© Copyright 2003 The Trustees of Indiana University. - Use, modification and distribution is subject to the Boost Software - License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at - http://www.boost.org/LICENSE_1_0.txt)

- - - - diff --git a/shared_iterator_example1.cpp b/shared_iterator_example1.cpp deleted file mode 100644 index f88e094..0000000 --- a/shared_iterator_example1.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2003 The Trustees of Indiana University. - -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#include "boost/shared_container_iterator.hpp" -#include "boost/shared_ptr.hpp" -#include -#include -#include - -typedef boost::shared_container_iterator< std::vector > 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 deleted file mode 100644 index a957707..0000000 --- a/shared_iterator_example2.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2003 The Trustees of Indiana University. - -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#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 deleted file mode 100644 index 5615d45..0000000 --- a/shared_iterator_example3.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2003 The Trustees of Indiana University. - -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -#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< std::vector > 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() { - - - iterator i,end; - - boost::tie(i,end) = return_range(); - - std::copy(i,end,std::ostream_iterator(std::cout,",")); - std::cout.put('\n'); - - return 0; -} diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 35619b1..7fd5b2f 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -23,8 +23,6 @@ run operators_test.cpp ; compile result_of_test.cpp ; -run shared_iterator_test.cpp ; - # compile-fail string_ref_from_rvalue.cpp ; run string_ref_test1.cpp ; run string_ref_test2.cpp ; diff --git a/test/shared_iterator_test.cpp b/test/shared_iterator_test.cpp deleted file mode 100644 index ff5b9c6..0000000 --- a/test/shared_iterator_test.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2003 The Trustees of Indiana University. - -// Use, modification and distribution is subject to the Boost Software -// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// Shared container iterator adaptor -// Author: Ronald Garcia -// See http://boost.org/libs/utility/shared_container_iterator.html -// for documentation. - -// -// shared_iterator_test.cpp - Regression tests for shared_container_iterator. -// - - -#include "boost/shared_container_iterator.hpp" -#include "boost/shared_ptr.hpp" -#include -#include - -struct resource { - static int count; - resource() { ++count; } - resource(resource const&) { ++count; } - ~resource() { --count; } -}; -int resource::count = 0; - -typedef std::vector resources_t; - -typedef boost::shared_container_iterator< resources_t > iterator; - - -void set_range(iterator& i, iterator& end) { - - boost::shared_ptr< resources_t > objs(new resources_t()); - - for (int j = 0; j != 6; ++j) - objs->push_back(resource()); - - i = iterator(objs->begin(),objs); - end = iterator(objs->end(),objs); - assert(resource::count == 6); -} - - -int main() { - - assert(resource::count == 0); - - { - iterator i; - { - iterator end; - set_range(i,end); - assert(resource::count == 6); - } - assert(resource::count == 6); - } - assert(resource::count == 0); - - return 0; -}