CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Wed, 23 Jul 2025 20:29:12 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20110812084328
location: https://web.archive.org/web/20110812084328/https://wiki.python.org/moin/boost.python/iterator
server-timing: captures_list;dur=1.185156, exclusion.robots;dur=0.032410, exclusion.robots.policy;dur=0.013258, esindex;dur=0.034846, cdx.remote;dur=70.136225, LoadShardBlock;dur=1180.361798, PetaboxLoader3.datanode;dur=223.130079, PetaboxLoader3.resolve;dur=261.701887
x-app-server: wwwb-app210
x-ts: 302
x-tr: 1281
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app210; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Wed, 23 Jul 2025 20:29:14 GMT
content-type: text/html; charset=utf-8
x-archive-orig-date: Fri, 12 Aug 2011 08:43:28 GMT
x-archive-orig-server: Apache/2.2.16 (Debian)
x-archive-orig-vary: Cookie,User-Agent,Accept-Language
x-archive-orig-set-cookie: MOIN_SESSION_80_ROOT_moin=732266a41297f0731bef06edd0e55c189b6f5dae; expires=Fri, 12-Aug-2011 09:43:00 GMT; Max-Age=3600; Path=/
x-archive-orig-content-length: 13702
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Fri, 12 Aug 2011 08:43:28 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Tue, 12 Sep 2006 01:23:35 GMT", ; rel="prev memento"; datetime="Thu, 17 Dec 2009 21:13:21 GMT", ; rel="memento"; datetime="Fri, 12 Aug 2011 08:43:28 GMT", ; rel="next memento"; datetime="Sat, 12 Nov 2011 21:24:38 GMT", ; rel="last memento"; datetime="Wed, 14 Feb 2024 17:29:10 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: WPO-20110812072219-crawl438/WPO-20110812084231-01709.warc.gz
server-timing: captures_list;dur=0.751553, exclusion.robots;dur=0.030894, exclusion.robots.policy;dur=0.013998, esindex;dur=0.013229, cdx.remote;dur=107.583584, LoadShardBlock;dur=527.853135, PetaboxLoader3.resolve;dur=360.668834, PetaboxLoader3.datanode;dur=268.391170, load_resource;dur=159.146842
x-app-server: wwwb-app210
x-ts: 200
x-tr: 859
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
boost.python/iterator - PythonInfo Wiki
User
C++ Iterators
Python iterator support a highly flexible interface allowing:
- Direct exposure of a class' begin() and end() functions:
... .def("__iter__", iterator<list_int>())
- Creation of iterators from member functions...
... .def("__iter__" , range(&my_class::x_begin, &my_class::x_end))
- ...and member data:
... .def("__iter__" , range(&std::pair<char*,char*>::first, &std::pair<char*,char*>::second))
The ability to specify boost.python/CallPolicy, e.g. to prevent copying of heavyweight values:
... .def("__iter__" , range<return_value_policy<copy_non_const_reference> >( &my_sequence<heavy>::begin , &my_sequence<heavy>::end))
Custom Iterators
Suppose we have custom iterator class providing next() member function. To expose it let's take an approach from scitbx package:
inline object pass_through(object const& o) { return o; } template<class Klass, class KlassIter> struct iterator_wrappers { static Klass next(KlassIter& o) { Klass* result = o.next(); if (!result) { PyErr_SetString(PyExc_StopIteration, "No more data."); boost::python::throw_error_already_set(); } return *result; } static void wrap(const char* python_name) { //using namespace boost::python; class_<KlassIter>(python_name, no_init) .def("next", next) .def("__iter__", pass_through) ; } }; BOOST_PYTHON_MODULE(iter) { ... iterator_wrappers<const MyClass,MyIter>().wrap("Iterator"); }
boost.python/iterator (last edited 2008-11-15 14:00:53 by localhost)