object demand_iterator_class(char const* name, Iterator* = 0, NextPolicies const& policies = NextPolicies()) { typedef iterator_range<NextPolicies,Iterator> range_; // Check the registry. If one is already registered, return it. handle<> class_obj( objects::registered_class_object(python::type_id<range_>())); if (class_obj.get() != 0) return object(class_obj); typedef typename range_::next_fn next_fn; typedef typename next_fn::result_type result_type; return class_<range_>(name, no_init) .def("__iter__", identity_function()) .def( #if PY_VERSION_HEX >= 0x03000000 "__next__" #else "next" #endif , make_function( next_fn() , policies , mpl::vector2<result_type,range_&>() )); }
object demand_iterator_class(char const* name, Iterator* = 0, NextPolicies const& policies = NextPolicies()) { typedef iterator_range<NextPolicies,Iterator> range_; // Check the registry. If one is already registered, return it. handle<> class_obj( objects::registered_class_object(python::type_id<range_>())); if (class_obj.get() != 0) return object(class_obj); // Make a callable object which can be used as the iterator's next() function. object next_function = objects::function_object( bind(&detail::iterator_next<Iterator,NextPolicies>::execute, _1, _2, policies) , 1); return class_<range_>(name, no_init) .def("__iter__", identity_function()) .setattr("next", next_function) ; }