[C++-sig] Re: iterator interface question (progress!)
Neal D. Becker
nbecker at hns.com
Fri Jan 30 19:57:38 CET 2004
I have made some progress, I am really impressed with boost python capabilities!
typedef std::vector<double>::iterator vd_it;
class_<vd_it>("DVecIter")
;
class_<std::vector<double> >("DVec")
.def(init<size_t>())
.def(vector_indexing_suite<std::vector<double> >())
.def("begin", (vd_it (std::vector<double>::*)())(&std::vector<double>::begin))
.def("end", (vd_it (std::vector<double>::*)())(&std::vector<double>::end))
;
typedef std::vector<Complex>::iterator vc_it;
class_<vc_it>("CVecIter")
;
class_<std::vector<Complex> >("CVec")
.def(init<size_t>())
.def(vector_indexing_suite<std::vector<Complex>, true >())
.def("begin", (vc_it (std::vector<Complex>::*)())(&std::vector<Complex>::begin))
.def("end", (vc_it (std::vector<Complex>::*)())(&std::vector<Complex>::end))
;
[...]
Just with this, my main goal is accomplished:
>>> from Test import *
>>> a = DVec (2)
>>> for x in range (0, len (a)): a[x] = x
>>> PrintV (a.begin(), a.end())
0
1
(where PrintV is a C++ function taking a pair of std::vector<double> iterators)
Now to see if I can teach python more tricks to do with DVecIter (e.g., arithmetic)
More information about the Cplusplus-sig
mailing list