CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Thu, 17 Jul 2025 13:50:26 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20071118171817
location: https://web.archive.org/web/20071118171817/https://wiki.python.org/moin/boost.python/iterator
server-timing: captures_list;dur=0.692854, exclusion.robots;dur=0.024594, exclusion.robots.policy;dur=0.011360, esindex;dur=0.013275, cdx.remote;dur=56.812232, LoadShardBlock;dur=401.969004, PetaboxLoader3.datanode;dur=244.075814
x-app-server: wwwb-app214
x-ts: 302
x-tr: 519
server-timing: TR;dur=0,Tw;dur=488,Tc;dur=0
set-cookie: SERVER=wwwb-app214; 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: Thu, 17 Jul 2025 13:50:28 GMT
content-type: text/html;charset=utf-8
x-archive-orig-date: Sun, 18 Nov 2007 17:18:17 GMT
x-archive-orig-server: Apache/2.0.54 (Debian GNU/Linux) mod_fastcgi/2.4.2
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Sun, 18 Nov 2007 17:18:17 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="Tue, 07 Aug 2007 06:32:15 GMT", ; rel="memento"; datetime="Sun, 18 Nov 2007 17:18:17 GMT", ; rel="next memento"; datetime="Fri, 28 Dec 2007 04:49:54 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_0_20071118134322_crawl102-c/51_0_20071118171010_crawl107.arc.gz
server-timing: captures_list;dur=0.776319, exclusion.robots;dur=0.025311, exclusion.robots.policy;dur=0.012225, esindex;dur=0.013914, cdx.remote;dur=291.670652, LoadShardBlock;dur=531.243984, PetaboxLoader3.datanode;dur=516.785624, PetaboxLoader3.resolve;dur=266.009199, load_resource;dur=565.793853
x-app-server: wwwb-app214
x-ts: 200
x-tr: 1498
server-timing: TR;dur=0,Tw;dur=534,Tc;dur=1
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
boost.python/iterator
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)
DeleteCache (cached 2007-09-06 02:48:45)- Login
- Navigation
- Actions
- Your recent pages