CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Fri, 18 Jul 2025 19:52:21 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20091217211321
location: https://web.archive.org/web/20091217211321/https://wiki.python.org/moin/boost.python/iterator
server-timing: captures_list;dur=0.675507, exclusion.robots;dur=0.027781, exclusion.robots.policy;dur=0.011720, esindex;dur=0.014592, cdx.remote;dur=6.476101, LoadShardBlock;dur=296.361664, PetaboxLoader3.datanode;dur=100.614045, PetaboxLoader3.resolve;dur=156.152466
x-app-server: wwwb-app211
x-ts: 302
x-tr: 332
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=1
set-cookie: SERVER=wwwb-app211; 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: Fri, 18 Jul 2025 19:52:22 GMT
content-type: text/html; charset=utf-8
x-archive-orig-date: Thu, 17 Dec 2009 21:13:21 GMT
x-archive-orig-server: Apache/2.2.9 (Debian) mod_fastcgi/2.4.6 mod_python/3.3.1 Python/2.5.2 mod_wsgi/2.5
x-archive-orig-vary: Cookie,User-Agent,Accept-Language
x-archive-orig-content-length: 11655
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Thu, 17 Dec 2009 21:13:21 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="Mon, 06 Jul 2009 10:44:58 GMT", ; rel="memento"; datetime="Thu, 17 Dec 2009 21:13:21 GMT", ; rel="next memento"; datetime="Fri, 12 Aug 2011 08:43:28 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: 51_13_20091217144415_crawl102-c/51_13_20091217211219_crawl103.arc.gz
server-timing: captures_list;dur=0.582688, exclusion.robots;dur=0.025187, exclusion.robots.policy;dur=0.012644, esindex;dur=0.013748, cdx.remote;dur=53.462476, LoadShardBlock;dur=420.302030, PetaboxLoader3.resolve;dur=264.217688, PetaboxLoader3.datanode;dur=301.442847, load_resource;dur=181.210360
x-app-server: wwwb-app211
x-ts: 200
x-tr: 718
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
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"); }
EditText (last edited 2008-11-15 14:00:53 by localhost)