CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Sat, 19 Jul 2025 05:41:09 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20071228044954
location: https://web.archive.org/web/20071228044954/https://wiki.python.org/moin/boost.python/iterator
server-timing: captures_list;dur=0.474354, exclusion.robots;dur=0.015721, exclusion.robots.policy;dur=0.008006, esindex;dur=0.010232, cdx.remote;dur=103.818303, LoadShardBlock;dur=308.626095, PetaboxLoader3.resolve;dur=190.087417, PetaboxLoader3.datanode;dur=95.866678
x-app-server: wwwb-app222
x-ts: 302
x-tr: 433
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app222; 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: Sat, 19 Jul 2025 05:41:10 GMT
content-type: text/html;charset=utf-8
x-archive-orig-date: Fri, 28 Dec 2007 04:49:54 GMT
x-archive-orig-server: Apache/2.2.3 (Debian) mod_fastcgi/2.4.2
x-archive-orig-pragma: no-cache
x-archive-orig-cache-control: no-cache
x-archive-orig-expires: -1
x-archive-orig-vary: Accept-Language,Cookie,User-Agent
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Fri, 28 Dec 2007 04:49:54 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="Sun, 18 Nov 2007 17:18:17 GMT", ; rel="memento"; datetime="Fri, 28 Dec 2007 04:49:54 GMT", ; rel="next memento"; datetime="Thu, 16 Oct 2008 12:06:52 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_1_20071228021341_crawl107-c/51_1_20071228044559_crawl107.arc.gz
server-timing: captures_list;dur=0.760423, exclusion.robots;dur=0.026949, exclusion.robots.policy;dur=0.012444, esindex;dur=0.014069, cdx.remote;dur=9.703036, LoadShardBlock;dur=245.442016, PetaboxLoader3.resolve;dur=395.973671, PetaboxLoader3.datanode;dur=82.218042, load_resource;dur=294.128599
x-app-server: wwwb-app222
x-ts: 200
x-tr: 594
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 2002-11-16 00:42:35 by MikeRovner)
- Login
- Navigation
- Actions
- Your recent pages