[C++-sig] iterator interface question
Neal D. Becker
nbecker at hns.com
Thu Jan 29 17:33:58 CET 2004
How to I interface algorithms with STL style iterator interface to python?
For example:
typedef std::complex<double> Complex;
//expose std::vector<Complex> to python:
//also let's pick a simple example function:
inline Complex Sum (const std::vector<Complex>::iterator& beg, const std::vector<Complex>::iterator& end) {
Complex sum = 0;
return std::accumulate (beg, end, sum);
}
BOOST_PYTHON_MODULE(Test)
{
class_<std::vector<std::complex<double> > >("CVec")
.def(init<size_t>())
.def(vector_indexing_suite<std::vector<std::complex<double> >, true >())
;
def ("accumulate", Sum);
}
Actually 2 questions:
1) How do I call accumulate from python?
2) (really a c++ question) How can I avoid introducing the "Sum" function? If I put
def ("accumulate", std::accumulate<const std::vector<Complex>::iterator&, Complex>)
I get
Test.cc:115: error: no matching function for call to `def(const char[11],
<unknown type>)'
Problem is it's overloaded, I guess, but I don't know what to do.
More information about the Cplusplus-sig
mailing list