Squashed 'third_party/boostorg/iterator/' content from commit b2adecb

Change-Id: I284a73816f9cc846742923879275b84c6e0c915c
git-subtree-dir: third_party/boostorg/iterator
git-subtree-split: b2adecb951af025698618f19a3c838bd314966dc
diff --git a/example/counting_iterator_example.cpp b/example/counting_iterator_example.cpp
new file mode 100644
index 0000000..c7d8add
--- /dev/null
+++ b/example/counting_iterator_example.cpp
@@ -0,0 +1,52 @@
+// (C) Copyright Jeremy Siek 2000-2004.
+// Distributed under 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/config.hpp>
+#include <algorithm>
+#include <iostream>
+#include <iterator>
+#include <vector>
+#include <boost/iterator/counting_iterator.hpp>
+#include <boost/iterator/indirect_iterator.hpp>
+#include <boost/cstdlib.hpp>
+
+int main(int, char*[])
+{
+  // Example of using counting_iterator
+  std::cout << "counting from 0 to 4:" << std::endl;
+  boost::counting_iterator<int> first(0), last(4);
+  std::copy(first, last, std::ostream_iterator<int>(std::cout, " "));
+  std::cout << std::endl;
+
+  // Example of using counting iterator to create an array of pointers.
+  int N = 7;
+  std::vector<int> numbers;
+  typedef std::vector<int>::iterator n_iter;
+  // Fill "numbers" array with [0,N)
+  std::copy(
+      boost::counting_iterator<int>(0)
+      , boost::counting_iterator<int>(N)
+      , std::back_inserter(numbers));
+
+  std::vector<std::vector<int>::iterator> pointers;
+
+  // Use counting iterator to fill in the array of pointers.
+  // causes an ICE with MSVC6
+  std::copy(boost::make_counting_iterator(numbers.begin()),
+            boost::make_counting_iterator(numbers.end()),
+            std::back_inserter(pointers));
+
+  // Use indirect iterator to print out numbers by accessing
+  // them through the array of pointers.
+  std::cout << "indirectly printing out the numbers from 0 to " 
+            << N << std::endl;
+  std::copy(boost::make_indirect_iterator(pointers.begin()),
+            boost::make_indirect_iterator(pointers.end()),
+            std::ostream_iterator<int>(std::cout, " "));
+  std::cout << std::endl;
+  
+  return boost::exit_success;
+}
diff --git a/example/filter_iterator_example.cpp b/example/filter_iterator_example.cpp
new file mode 100644
index 0000000..8880c8d
--- /dev/null
+++ b/example/filter_iterator_example.cpp
@@ -0,0 +1,58 @@
+//  (C) Copyright Jeremy Siek 1999-2004.
+// Distributed under 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/config.hpp>
+#include <algorithm>
+#include <functional>
+#include <iostream>
+#include <boost/iterator/filter_iterator.hpp>
+#include <boost/cstdlib.hpp> // for exit_success
+
+struct is_positive_number {
+  bool operator()(int x) { return 0 < x; }
+};
+
+int main()
+{
+  int numbers_[] = { 0, -1, 4, -3, 5, 8, -2 };
+  const int N = sizeof(numbers_)/sizeof(int);
+  
+  typedef int* base_iterator;
+  base_iterator numbers(numbers_);
+  
+  // Example using make_filter_iterator()
+  std::copy(boost::make_filter_iterator<is_positive_number>(numbers, numbers + N),
+            boost::make_filter_iterator<is_positive_number>(numbers + N, numbers + N),
+            std::ostream_iterator<int>(std::cout, " "));
+  std::cout << std::endl;
+
+  // Example using filter_iterator
+  typedef boost::filter_iterator<is_positive_number, base_iterator>
+    FilterIter;
+  
+  is_positive_number predicate;
+  FilterIter filter_iter_first(predicate, numbers, numbers + N);
+  FilterIter filter_iter_last(predicate, numbers + N, numbers + N);
+
+  std::copy(filter_iter_first, filter_iter_last, std::ostream_iterator<int>(std::cout, " "));
+  std::cout << std::endl;
+
+  // Another example using make_filter_iterator()
+  std::copy(
+      boost::make_filter_iterator(
+          std::bind2nd(std::greater<int>(), -2)
+        , numbers, numbers + N)
+            
+    , boost::make_filter_iterator(
+          std::bind2nd(std::greater<int>(), -2)
+        , numbers + N, numbers + N)
+      
+    , std::ostream_iterator<int>(std::cout, " ")
+  );
+  
+  std::cout << std::endl;
+  
+  return boost::exit_success;
+}
diff --git a/example/func_output_iter_example.cpp b/example/func_output_iter_example.cpp
new file mode 100644
index 0000000..9c06319
--- /dev/null
+++ b/example/func_output_iter_example.cpp
@@ -0,0 +1,46 @@
+// (C) Copyright Jeremy Siek 2001-2004.
+// Distributed under 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)
+
+// Revision History:
+
+// 27 Feb 2001   Jeremy Siek
+//      Initial checkin.
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include <boost/function_output_iterator.hpp>
+
+struct string_appender
+{
+    string_appender(std::string& s)
+        : m_str(&s)
+    {}
+    
+    void operator()(const std::string& x) const
+    {
+        *m_str += x;
+    }
+
+    std::string* m_str;
+};
+
+int main(int, char*[])
+{
+  std::vector<std::string> x;
+  x.push_back("hello");
+  x.push_back(" ");
+  x.push_back("world");
+  x.push_back("!");
+
+  std::string s = "";
+  std::copy(x.begin(), x.end(), 
+            boost::make_function_output_iterator(string_appender(s)));
+  
+  std::cout << s << std::endl;
+
+  return 0;
+}
diff --git a/example/indirect_iterator_example.cpp b/example/indirect_iterator_example.cpp
new file mode 100644
index 0000000..abbf46c
--- /dev/null
+++ b/example/indirect_iterator_example.cpp
@@ -0,0 +1,59 @@
+// (C) Copyright Jeremy Siek 2000-2004.
+// Distributed under 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/config.hpp>
+#include <vector>
+#include <iostream>
+#include <iterator>
+#include <functional>
+#include <algorithm>
+#include <boost/iterator/indirect_iterator.hpp>
+
+int main(int, char*[])
+{
+  char characters[] = "abcdefg";
+  const int N = sizeof(characters)/sizeof(char) - 1; // -1 since characters has a null char
+  char* pointers_to_chars[N];                        // at the end.
+  for (int i = 0; i < N; ++i)
+    pointers_to_chars[i] = &characters[i];
+
+  // Example of using indirect_iterator
+  
+  boost::indirect_iterator<char**, char>
+    indirect_first(pointers_to_chars), indirect_last(pointers_to_chars + N);
+
+  std::copy(indirect_first, indirect_last, std::ostream_iterator<char>(std::cout, ","));
+  std::cout << std::endl;
+  
+
+  // Example of making mutable and constant indirect iterators
+
+  char mutable_characters[N];
+  char* pointers_to_mutable_chars[N];
+  for (int j = 0; j < N; ++j)
+    pointers_to_mutable_chars[j] = &mutable_characters[j];
+
+  boost::indirect_iterator<char* const*> mutable_indirect_first(pointers_to_mutable_chars),
+    mutable_indirect_last(pointers_to_mutable_chars + N);
+  boost::indirect_iterator<char* const*, char const> const_indirect_first(pointers_to_chars),
+    const_indirect_last(pointers_to_chars + N);
+
+  std::transform(const_indirect_first, const_indirect_last,
+                 mutable_indirect_first, std::bind1st(std::plus<char>(), 1));
+
+  std::copy(mutable_indirect_first, mutable_indirect_last,
+            std::ostream_iterator<char>(std::cout, ","));
+  std::cout << std::endl;
+
+  
+  // Example of using make_indirect_iterator()
+
+  std::copy(boost::make_indirect_iterator(pointers_to_chars), 
+            boost::make_indirect_iterator(pointers_to_chars + N),
+            std::ostream_iterator<char>(std::cout, ","));
+  std::cout << std::endl;
+  
+  return 0;
+}
diff --git a/example/node.hpp b/example/node.hpp
new file mode 100644
index 0000000..c3ed315
--- /dev/null
+++ b/example/node.hpp
@@ -0,0 +1,60 @@
+// Copyright David Abrahams 2004. 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)
+#ifndef NODE_DWA2004110_HPP
+# define NODE_DWA2004110_HPP
+
+# include <iostream>
+
+// Polymorphic list node base class
+
+struct node_base
+{
+    node_base() : m_next(0) {}
+
+    virtual ~node_base()
+    {
+        delete m_next;
+    }
+
+    node_base* next() const
+    {
+        return m_next;
+    }
+
+    virtual void print(std::ostream& s) const = 0;
+    virtual void double_me() = 0;
+        
+    void append(node_base* p)
+    {
+        if (m_next)
+            m_next->append(p);
+        else
+            m_next = p;
+    }
+    
+ private:
+    node_base* m_next;
+};
+
+inline std::ostream& operator<<(std::ostream& s, node_base const& n)
+{
+    n.print(s);
+    return s;
+}
+
+template <class T>
+struct node : node_base
+{
+    node(T x)
+      : m_value(x)
+    {}
+
+    void print(std::ostream& s) const { s << this->m_value; }
+    void double_me() { m_value += m_value; }
+    
+ private:
+    T m_value;
+};
+    
+#endif // NODE_DWA2004110_HPP
diff --git a/example/node_iterator1.cpp b/example/node_iterator1.cpp
new file mode 100644
index 0000000..94b34e8
--- /dev/null
+++ b/example/node_iterator1.cpp
@@ -0,0 +1,44 @@
+// Copyright David Abrahams 2004. 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 "node_iterator1.hpp"
+#include <string>
+#include <memory>
+#include <iostream>
+#include <algorithm>
+#include <functional>
+
+int main()
+{
+
+#if defined(BOOST_NO_CXX11_SMART_PTR)
+
+    std::auto_ptr<node<int> > nodes(new node<int>(42));
+    
+#else
+
+    std::unique_ptr<node<int> > nodes(new node<int>(42));
+    
+#endif
+
+    nodes->append(new node<std::string>(" is greater than "));
+    nodes->append(new node<int>(13));
+
+    std::copy(
+        node_iterator(nodes.get()), node_iterator()
+      , std::ostream_iterator<node_base>(std::cout, " ")
+    );
+    std::cout << std::endl;
+    
+    std::for_each(
+        node_iterator(nodes.get()), node_iterator()
+      , std::mem_fun_ref(&node_base::double_me)
+    );
+
+    std::copy(
+        node_iterator(nodes.get()), node_iterator()
+      , std::ostream_iterator<node_base>(std::cout, "/")
+    );
+    std::cout << std::endl;
+}
diff --git a/example/node_iterator1.hpp b/example/node_iterator1.hpp
new file mode 100644
index 0000000..5e068b4
--- /dev/null
+++ b/example/node_iterator1.hpp
@@ -0,0 +1,42 @@
+// Copyright David Abrahams 2004. 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)
+#ifndef NODE_ITERATOR1_DWA2004110_HPP
+# define NODE_ITERATOR1_DWA2004110_HPP
+
+# include "node.hpp"
+# include <boost/iterator/iterator_facade.hpp>
+
+class node_iterator
+  : public boost::iterator_facade<
+        node_iterator
+      , node_base
+      , boost::forward_traversal_tag
+    >
+{
+ public:
+    node_iterator()
+      : m_node(0)
+    {}
+
+    explicit node_iterator(node_base* p)
+      : m_node(p)
+    {}
+
+ private:
+    friend class boost::iterator_core_access;
+
+    void increment()
+    { m_node = m_node->next(); }
+    
+    bool equal(node_iterator const& other) const
+    { return this->m_node == other.m_node; }
+    
+    node_base& dereference() const
+    { return *m_node; }
+
+    node_base* m_node;
+};
+
+
+#endif // NODE_ITERATOR1_DWA2004110_HPP
diff --git a/example/node_iterator2.cpp b/example/node_iterator2.cpp
new file mode 100644
index 0000000..f8f873e
--- /dev/null
+++ b/example/node_iterator2.cpp
@@ -0,0 +1,53 @@
+// Copyright David Abrahams 2004. 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 "node_iterator2.hpp"
+#include <string>
+#include <memory>
+#include <iostream>
+#include <algorithm>
+#include <boost/mem_fn.hpp>
+#include <cassert>
+
+int main()
+{
+
+#if defined(BOOST_NO_CXX11_SMART_PTR)
+
+    std::auto_ptr<node<int> > nodes(new node<int>(42));
+    
+#else
+
+    std::unique_ptr<node<int> > nodes(new node<int>(42));
+    
+#endif
+
+    nodes->append(new node<std::string>(" is greater than "));
+    nodes->append(new node<int>(13));
+
+    // Check interoperability
+    assert(node_iterator(nodes.get()) == node_const_iterator(nodes.get()));
+    assert(node_const_iterator(nodes.get()) == node_iterator(nodes.get()));
+    
+    assert(node_iterator(nodes.get()) != node_const_iterator());
+    assert(node_const_iterator(nodes.get()) != node_iterator());
+    
+    std::copy(
+        node_iterator(nodes.get()), node_iterator()
+      , std::ostream_iterator<node_base>(std::cout, " ")
+    );
+    std::cout << std::endl;
+    
+    std::for_each(
+        node_iterator(nodes.get()), node_iterator()
+      , boost::mem_fn(&node_base::double_me)
+    );
+
+    std::copy(
+        node_const_iterator(nodes.get()), node_const_iterator()
+      , std::ostream_iterator<node_base>(std::cout, "/")
+    );
+    std::cout << std::endl;
+    return 0;
+}
diff --git a/example/node_iterator2.hpp b/example/node_iterator2.hpp
new file mode 100644
index 0000000..6aa0a4c
--- /dev/null
+++ b/example/node_iterator2.hpp
@@ -0,0 +1,73 @@
+// Copyright David Abrahams 2004. 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)
+#ifndef NODE_ITERATOR2_DWA2004110_HPP
+# define NODE_ITERATOR2_DWA2004110_HPP
+
+# include "node.hpp"
+# include <boost/iterator/iterator_facade.hpp>
+
+# ifndef BOOST_NO_SFINAE
+#  include <boost/type_traits/is_convertible.hpp>
+#  include <boost/utility/enable_if.hpp>
+# endif
+
+template <class Value>
+class node_iter
+  : public boost::iterator_facade<
+        node_iter<Value>
+      , Value
+      , boost::forward_traversal_tag
+    >
+{
+ private:
+    struct enabler {};  // a private type avoids misuse
+
+ public:
+    node_iter()
+      : m_node(0) {}
+
+    explicit node_iter(Value* p)
+      : m_node(p) {}
+
+    template <class OtherValue>
+    node_iter(
+        node_iter<OtherValue> const& other
+# ifndef BOOST_NO_SFINAE
+      , typename boost::enable_if<
+            boost::is_convertible<OtherValue*,Value*>
+          , enabler
+        >::type = enabler()
+# endif 
+    )
+      : m_node(other.m_node) {}
+
+
+# if !BOOST_WORKAROUND(__GNUC__, == 2)
+ private: // GCC2 can't grant friendship to template member functions    
+    friend class boost::iterator_core_access;
+# endif 
+
+    template <class OtherValue>
+    bool equal(node_iter<OtherValue> const& other) const
+    {
+        return this->m_node == other.m_node;
+    }
+
+    void increment() { m_node = m_node->next(); }
+
+    Value& dereference() const { return *m_node; }
+
+# ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
+ public:
+# else
+ private:
+    template <class> friend class node_iter;
+# endif 
+    Value* m_node;
+};
+
+typedef node_iter<node_base> node_iterator;
+typedef node_iter<node_base const> node_const_iterator;
+
+#endif // NODE_ITERATOR2_DWA2004110_HPP
diff --git a/example/node_iterator3.cpp b/example/node_iterator3.cpp
new file mode 100644
index 0000000..7cb4238
--- /dev/null
+++ b/example/node_iterator3.cpp
@@ -0,0 +1,53 @@
+// Copyright David Abrahams 2004. 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 "node_iterator3.hpp"
+#include <string>
+#include <memory>
+#include <iostream>
+#include <algorithm>
+#include <boost/mem_fn.hpp>
+#include <cassert>
+
+int main()
+{
+
+#if defined(BOOST_NO_CXX11_SMART_PTR)
+
+    std::auto_ptr<node<int> > nodes(new node<int>(42));
+    
+#else
+
+    std::unique_ptr<node<int> > nodes(new node<int>(42));
+    
+#endif
+
+    nodes->append(new node<std::string>(" is greater than "));
+    nodes->append(new node<int>(13));
+
+    // Check interoperability
+    assert(node_iterator(nodes.get()) == node_const_iterator(nodes.get()));
+    assert(node_const_iterator(nodes.get()) == node_iterator(nodes.get()));
+    
+    assert(node_iterator(nodes.get()) != node_const_iterator());
+    assert(node_const_iterator(nodes.get()) != node_iterator());
+    
+    std::copy(
+        node_iterator(nodes.get()), node_iterator()
+      , std::ostream_iterator<node_base>(std::cout, " ")
+    );
+    std::cout << std::endl;
+    
+    std::for_each(
+        node_iterator(nodes.get()), node_iterator()
+      , boost::mem_fn(&node_base::double_me)
+    );
+
+    std::copy(
+        node_const_iterator(nodes.get()), node_const_iterator()
+      , std::ostream_iterator<node_base>(std::cout, "/")
+    );
+    std::cout << std::endl;
+    return 0;
+}
diff --git a/example/node_iterator3.hpp b/example/node_iterator3.hpp
new file mode 100644
index 0000000..85127e1
--- /dev/null
+++ b/example/node_iterator3.hpp
@@ -0,0 +1,60 @@
+// Copyright David Abrahams 2004. 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)
+#ifndef NODE_ITERATOR3_DWA2004110_HPP
+# define NODE_ITERATOR3_DWA2004110_HPP
+
+# include "node.hpp"
+# include <boost/iterator/iterator_adaptor.hpp>
+
+# ifndef BOOST_NO_SFINAE
+#  include <boost/type_traits/is_convertible.hpp>
+#  include <boost/utility/enable_if.hpp>
+# endif
+
+template <class Value>
+class node_iter
+  : public boost::iterator_adaptor<
+        node_iter<Value>                // Derived
+      , Value*                          // Base
+      , boost::use_default              // Value
+      , boost::forward_traversal_tag    // CategoryOrTraversal
+    >
+{
+ private:
+    struct enabler {};  // a private type avoids misuse
+
+    typedef boost::iterator_adaptor<
+        node_iter<Value>, Value*, boost::use_default, boost::forward_traversal_tag
+    > super_t;
+    
+ public:
+    node_iter()
+      : super_t(0) {}
+
+    explicit node_iter(Value* p)
+      : super_t(p) {}
+
+    template <class OtherValue>
+    node_iter(
+        node_iter<OtherValue> const& other
+# ifndef BOOST_NO_SFINAE
+      , typename boost::enable_if<
+            boost::is_convertible<OtherValue*,Value*>
+          , enabler
+        >::type = enabler()
+# endif 
+    )
+      : super_t(other.base()) {}
+
+# if !BOOST_WORKAROUND(__GNUC__, == 2)
+ private: // GCC2 can't grant friendship to template member functions    
+    friend class boost::iterator_core_access;
+# endif     
+    void increment() { this->base_reference() = this->base()->next(); }
+};
+
+typedef node_iter<node_base> node_iterator;
+typedef node_iter<node_base const> node_const_iterator;
+
+#endif // NODE_ITERATOR3_DWA2004110_HPP
diff --git a/example/permutation_iter_example.cpp b/example/permutation_iter_example.cpp
new file mode 100644
index 0000000..aad6125
--- /dev/null
+++ b/example/permutation_iter_example.cpp
@@ -0,0 +1,68 @@
+// Copyright (C) 2004 Jeremy Siek <jsiek@cs.indiana.edu>
+// Distributed under 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 <iostream>
+#include <vector>
+#include <deque>
+#include <algorithm>
+#include <boost/iterator/permutation_iterator.hpp>
+#include <boost/cstdlib.hpp>
+#include <assert.h>
+
+
+int main() {
+  using namespace boost;
+  int i = 0;
+
+  typedef std::vector< int > element_range_type;
+  typedef std::deque< int > index_type;
+
+  static const int element_range_size = 10;
+  static const int index_size = 4;
+
+  element_range_type elements( element_range_size );
+  for(element_range_type::iterator el_it = elements.begin() ; el_it != elements.end() ; ++el_it)
+    *el_it = std::distance(elements.begin(), el_it);
+
+  index_type indices( index_size );
+  for(index_type::iterator i_it = indices.begin() ; i_it != indices.end() ; ++i_it ) 
+    *i_it = element_range_size - index_size + std::distance(indices.begin(), i_it);
+  std::reverse( indices.begin(), indices.end() );
+
+  typedef permutation_iterator< element_range_type::iterator, index_type::iterator > permutation_type;
+  permutation_type begin = make_permutation_iterator( elements.begin(), indices.begin() );
+  permutation_type it = begin;
+  permutation_type end = make_permutation_iterator( elements.begin(), indices.end() );
+
+  std::cout << "The original range is : ";
+  std::copy( elements.begin(), elements.end(), std::ostream_iterator< int >( std::cout, " " ) );
+  std::cout << "\n";
+
+  std::cout << "The reindexing scheme is : ";
+  std::copy( indices.begin(), indices.end(), std::ostream_iterator< int >( std::cout, " " ) );
+  std::cout << "\n";
+
+  std::cout << "The permutated range is : ";
+  std::copy( begin, end, std::ostream_iterator< int >( std::cout, " " ) );
+  std::cout << "\n";
+
+  std::cout << "Elements at even indices in the permutation : ";
+  it = begin;
+  for(i = 0; i < index_size / 2 ; ++i, it+=2 ) std::cout << *it << " ";
+  std::cout << "\n";
+
+  std::cout << "Permutation backwards : ";
+  it = begin + (index_size);
+  assert( it != begin );
+  for( ; it-- != begin ; ) std::cout << *it << " ";
+  std::cout << "\n";
+
+  std::cout << "Iterate backward with stride 2 : ";
+  it = begin + (index_size - 1);
+  for(i = 0 ; i < index_size / 2 ; ++i, it-=2 ) std::cout << *it << " ";
+  std::cout << "\n";
+
+  return boost::exit_success;
+}
diff --git a/example/reverse_iterator.cpp b/example/reverse_iterator.cpp
new file mode 100644
index 0000000..b5f10f7
--- /dev/null
+++ b/example/reverse_iterator.cpp
@@ -0,0 +1,19 @@
+// Copyright (C) 2004 Jeremy Siek <jsiek@cs.indiana.edu>
+// Distributed under 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/iterator/reverse_iterator.hpp>
+#include <boost/cstdlib.hpp>
+#include <iostream>
+#include <iterator>
+#include <algorithm>
+
+int main()
+{
+  int x[] = { 1, 2, 3, 4 };
+  boost::reverse_iterator<int*> first(x + 4), last(x);
+  std::copy(first, last, std::ostream_iterator<int>(std::cout, " "));
+  std::cout << std::endl;
+  return 0;
+}
diff --git a/example/reverse_iterator_example.cpp b/example/reverse_iterator_example.cpp
new file mode 100644
index 0000000..61b8c4f
--- /dev/null
+++ b/example/reverse_iterator_example.cpp
@@ -0,0 +1,41 @@
+// (C) Copyright Jeremy Siek 2000-2004.
+// Distributed under 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/config.hpp>
+#include <iostream>
+#include <algorithm>
+#include <boost/iterator/reverse_iterator.hpp>
+#include <boost/cstdlib.hpp>
+
+int main(int, char*[])
+{
+  char letters_[] = "hello world!";
+  const int N = sizeof(letters_)/sizeof(char) - 1;
+  typedef char* base_iterator;
+  base_iterator letters(letters_);
+  
+  std::cout << "original sequence of letters:\t\t\t"
+            << letters_ << std::endl;
+
+  // Use reverse_iterator to print a sequence of letters in reverse
+  // order.
+  
+  boost::reverse_iterator<base_iterator>
+    reverse_letters_first(letters + N),
+    reverse_letters_last(letters);
+
+  std::cout << "sequence in reverse order:\t\t\t";
+  std::copy(reverse_letters_first, reverse_letters_last,
+            std::ostream_iterator<char>(std::cout));
+  std::cout << std::endl;
+
+  std::cout << "sequence in double-reversed (normal) order:\t";
+  std::copy(boost::make_reverse_iterator(reverse_letters_last),
+            boost::make_reverse_iterator(reverse_letters_first),
+            std::ostream_iterator<char>(std::cout));
+  std::cout << std::endl;
+
+  return boost::exit_success;
+}
diff --git a/example/shared_iterator_example1.cpp b/example/shared_iterator_example1.cpp
new file mode 100644
index 0000000..f88e094
--- /dev/null
+++ b/example/shared_iterator_example1.cpp
@@ -0,0 +1,42 @@
+// 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 <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;
+}
diff --git a/example/shared_iterator_example2.cpp b/example/shared_iterator_example2.cpp
new file mode 100644
index 0000000..a957707
--- /dev/null
+++ b/example/shared_iterator_example2.cpp
@@ -0,0 +1,43 @@
+// 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 <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;
+}
diff --git a/example/shared_iterator_example3.cpp b/example/shared_iterator_example3.cpp
new file mode 100644
index 0000000..5615d45
--- /dev/null
+++ b/example/shared_iterator_example3.cpp
@@ -0,0 +1,41 @@
+// 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 <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;
+}
diff --git a/example/transform_iterator_example.cpp b/example/transform_iterator_example.cpp
new file mode 100644
index 0000000..ce1b413
--- /dev/null
+++ b/example/transform_iterator_example.cpp
@@ -0,0 +1,75 @@
+// (C) Copyright Jeremy Siek 2000-2004. 
+// Distributed under 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 <functional>
+#include <algorithm>
+#include <iostream>
+#include <boost/iterator/transform_iterator.hpp>
+
+// What a bummer. We can't use std::binder1st with transform iterator
+// because it does not have a default constructor. Here's a version
+// that does.
+
+namespace boost {
+
+  template <class Operation> 
+  class binder1st {
+  public:
+    typedef typename Operation::result_type result_type;
+    typedef typename Operation::second_argument_type argument_type;
+  protected:
+    Operation op;
+    typename Operation::first_argument_type value;
+  public:
+    binder1st() { } // this had to be added!
+    binder1st(const Operation& x,
+              const typename Operation::first_argument_type& y)
+        : op(x), value(y) {}
+    typename Operation::result_type
+    operator()(const typename Operation::second_argument_type& x) const {
+      return op(value, x);
+    }
+  };
+
+  template <class Operation, class T>
+  inline binder1st<Operation> bind1st(const Operation& op, const T& x) {
+    typedef typename Operation::first_argument_type arg1_type;
+    return binder1st<Operation>(op, arg1_type(x));
+  }
+
+} // namespace boost
+
+int
+main(int, char*[])
+{
+  // This is a simple example of using the transform_iterators class to
+  // generate iterators that multiply the value returned by dereferencing
+  // the iterator. In this case we are multiplying by 2.
+  // Would be cooler to use lambda library in this example.
+
+  int x[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
+  const int N = sizeof(x)/sizeof(int);
+
+  typedef boost::binder1st< std::multiplies<int> > Function;
+  typedef boost::transform_iterator<Function, int*> doubling_iterator;
+
+  doubling_iterator i(x, boost::bind1st(std::multiplies<int>(), 2)),
+    i_end(x + N, boost::bind1st(std::multiplies<int>(), 2));
+
+  std::cout << "multiplying the array by 2:" << std::endl;
+  while (i != i_end)
+    std::cout << *i++ << " ";
+  std::cout << std::endl;
+
+  std::cout << "adding 4 to each element in the array:" << std::endl;
+
+  std::copy(boost::make_transform_iterator(x, boost::bind1st(std::plus<int>(), 4)),
+            boost::make_transform_iterator(x + N, boost::bind1st(std::plus<int>(), 4)),
+            std::ostream_iterator<int>(std::cout, " "));
+  std::cout << std::endl;
+  
+  return 0;
+}