boost.python iterators

Dirk Steenpass <[email protected]>
Newsgroups gmane.comp.lib.boost.langbinding
Message-ID <[email protected]>
Dear all,

I am looking for a way to create a python savvy iterator by wrapping a
container that provides begin and end member functions taking arguments.

The reference manual entry on boost::python::range left me unsure whether
the appended code would compile (it does not).

The sentence:

"The first form creates a Python callable object which, when invoked, converts
its argument to a Target object x, and creates a Python iterator which
traverses [bind(start,_1)(x), bind(finish,_1)(x)), applying NextPolicies to the
iterator's next() function."

suggested to me that a single argument, i.e., the target reference is passed to
the accessor functions. This would imply that the accessor takes exactly one
argument. (???)

However, the subsequent explanations about the deduction of Target left me with
the impression that accessor functions and accessor member function pointers
may take several arguments.

Any help is appreciated,
dirk

//--- A [n] example -----------------------------------------------------------
// Does not compile with gcc 3.3.6 and gcc 4.0.2

#include <vector>

#include <boost/python.hpp>

using namespace std;
using namespace boost::python;

class A
{
public:
    typedef std::vector<int> VecInt;
    typedef VecInt::iterator Iter;
    typedef VecInt::size_type SizeType;

public:
    A(): vec_(100, 23) {}

    Iter Begin(SizeType ignored) { return vec_.begin(); }
    Iter End(SizeType ignored) { return vec_.end(); }

private:
    VecInt vec_;
};

BOOST_PYTHON_MODULE(A)
{
    class_<A>("A")
        .def("Elements", range(&A::Begin, &A::End))
        ;
}

// Just allowing standalone compilation.
int main(void)
{
    return 0;
}




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.