[C++-sig] Re: C arrays solution

David Abrahams dave at boost-consulting.com
Tue Oct 14 13:42:47 CEST 2003

"Niall Douglas" <s_sourceforge at nedprod.com> writes:

>> If you're satisfied with that, I guess I'm satisfied.  Otherwise,
>> perhaps you'd like to post a little more detail about how you want to
>> be able to *use* this code from Python?  I think people here,
>> especially Raoul, should be able to make some suggestions which would
>> solve the problem in a more principled way.
>>>> from TestCArrays import *
>>>> a=MyList()
>>>> b=a.getData()
>>>> print len(b)
> 4
>>>> print b[0:4]
> ['Niall', 'is', 'a', 'teapot']
>>>> b[1]="is not"
>>>> print b[0:4]
> ['Niall', 'is not', 'a', 'teapot']
> The key here is that MyList knows nothing of python and offers no 
> more than a C array of pointers, something which up until now was 
> hard to wrap without lots of munge code.

I'm not sure what "munge code" means.  The behavior you show above is
almost trivial to achieve using Boost.Python, without anything I
consider to be "munge code".

Question 1:  when you modify b above, do you expect it to affect a?

Question 2:  do you expect b to be an actual Python list,
             i.e. type(b) == list ??

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list