Boost
  C++ Libraries
  
  ...one of the most highly
  regarded and expertly designed C++ library projects in the
  world.
 — Herb Sutter and Andrei
  Alexandrescu, C++
  Coding Standards
stl_input_iteratorstl_input_iterator synopsisstl_input_iterator constructorsstl_input_iterator modifiersstl_input_iterator observers<boost/python/stl_iterator.hpp> provides types
    for creating C++
    Iterators from 
    Python iterables.
stl_input_iteratorInstances of stl_input_iterator<T> hold a Python
    iterator and adapt it for use with STL algorithms.
    stl_input_iterator<T> satisfies the requirements for
    an Input Iterator.
    
| Template Parameter | Requirements | Semantics | Default | 
|---|---|---|---|
ValueType | 
        ValueType must be CopyConstructible. | 
        Dereferencing an instance of stl_input_iterator<ValueType>
        will return an rvalue of type ValueType. | 
        None | 
namespace boost { namespace python
{
  template <class ValueType>
  struct stl_input_iterator
  {
      typedef std::ptrdiff_t difference_type;
      typedef ValueType value_type;
      typedef ValueType* pointer;
      typedef ValueType reference;
      typedef std::input_iterator_tag iterator_category;
      stl_input_iterator();
      stl_input_iterator(object const& ob);
      stl_input_iterator& operator++();
      stl_input_iterator operator++(int);
      ValueType operator*() const;
      friend bool operator==(stl_input_iterator const& lhs, stl_input_iterator const& rhs);
      friend bool operator!=(stl_input_iterator const& lhs, stl_input_iterator const& rhs);
  private:
      object it; // For exposition only
      object ob; // For exposition only
  };
}}
    stl_input_iterator
      constructors
    stl_input_iterator()
this is past-the-end.stl_input_iterator(object const& ob)
ob.attr("__iter__")() and stores the resulting Python iterator
        object in this->it. Then, calls this->it.attr("next")() and
        stores the result in this->ob. If the sequence is exhausted, sets
        this->ob to object().
      this is a dereferenceable or past-the-end.stl_input_iterator
      modifiers
    stl_input_iterator& operator++()
this->it.attr("next")() and stores the result in
        this->ob. If the sequence is exhausted, sets this->ob
        to object().
      this is a dereferenceable or past-the-end.*this.stl_input_iterator operator++(int)
stl_input_iterator tmp = *this; ++*this; return tmp;
      this is a dereferenceable or past-the-end.stl_input_iterator
    observersValueType operator*() const
extract<ValueType>(this->ob);
      friend bool operator==(stl_input_iterator const& lhs, stl_input_iterator const& rhs)
(lhs.ob == object()) == (rhs.ob == object())
      friend bool operator!=(stl_input_iterator const& lhs, stl_input_iterator const& rhs)
!(lhs == rhs)
      
#include <boost/python/object.hpp>
#include <boost/python/stl_iterator.hpp>
#include <list>
using namespace boost::python;
std::list<int> sequence_to_int_list(object const& ob)
{
    stl_input_iterator<int> begin(ob), end;
    return std::list<int>(begin, end);
}
Revised 30 October, 2005
© Copyright Eric Niebler 2005.