[C++-sig] Re: iterator interface question
by David Abrahams other posts by this author
Jan 30 2004 8:34AM messages near this date
[C++-sig] Re: iterator interface question
|
[C++-sig] Re: call python method from C++
"Neal D. Becker" <nbecker@[...].com> writes:
> 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?
Depends what you want to pass to it. In other words, how would you
*like* to 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>)'
That's a compiler bug probably, but nonetheless you're not allowed to
take the address of a function in the standard library, so answer:
"you can't"
> Problem is it's overloaded, I guess, but I don't know what to do.
Between the allowed overloading and extra default arguments,
forwarding is the only way.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
|