[C++-sig] How to expose operator[] in boost.python

Charles Solar charlessolar at gmail.com
Wed Sep 8 21:30:46 CEST 2010


Use the python special function __getitem__

So, something like this:

.def( "__getitem__", &Foo::operator[], boost::python::arg( "index" ),
boost::python::return_internal_reference<>() )

If you want your container iteratable, see the docs for boost::python::range.

Charles

On Wed, Sep 8, 2010 at 2:22 PM, Junwei Zhang <junweizhang2006 at gmail.com> wrote:
> Hi,
>
> If I have a class support operator[] and operator() for indexing purpose.
> How can I wrapper it in python?
>
> --
> Junwei Zhang
> Office Phone:402-472-1968
> junweizhang2006 at gmail.com
> www.junweizhang.com
> Department of Electrical Engineering
> University of Nebraska-Lincoln
> 209N Walter Scott Engineering Center
> P.O. Box 880511
> Lincoln, NE 68588-0511
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>


More information about the Cplusplus-sig mailing list