CARVIEW |
Select Language
HTTP/2 200
server: nginx
date: Sat, 19 Jul 2025 18:41:38 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.739218, exclusion.robots;dur=0.025556, exclusion.robots.policy;dur=0.010894, esindex;dur=0.015465, cdx.remote;dur=40.258029, LoadShardBlock;dur=111.329508, PetaboxLoader3.datanode;dur=104.946251, load_resource;dur=113.767173, PetaboxLoader3.resolve;dur=67.167819
x-app-server: wwwb-app212
x-ts: 200
x-tr: 318
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=1
set-cookie: SERVER=wwwb-app212; 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=()
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