[C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type:

David Abrahams dave at boost-consulting.com
Mon Aug 23 17:09:53 CEST 2004


"tALSit de CoD" <talsit at talsit.org> writes:

> Hmm... i've been trying to understand it, i've read the docs... but... 
> ummm... i can't quite understand it very well...
>
> Does this mean that when my class does:
>
> const std::vector <cNodeDescriptor *> cRegistry::getDescriptors ();
>
> i have to replace that with this:
>
> boost::indirect_iterator<std::vector<cNodeDescriptor*>::iterator> 
> cRegistry::getDescriptors ();

I have no idea what getDescriptors is, so it's hard to comment.

> Or am i just totally missing the point?
>
> Most of the template magic voodoo still baffels me... :D

There's no template magic voodoo to understand this.

  Try using range
  (http://www.boost.org/libs/python/doc/v2/iterator.html#range-spec) 

Do you understand what range does?

   with functions that return
   boost::indirect_iterator<std::vector<cNodeDescriptor*>::iterator>
   wrapped around the vector's begin() and end().
   (http://www.boost.org/libs/iterator/doc/indirect_iterator.html)

By this I mean
   
  boost::indirect_iterator<std::vector<cNodeDescriptor*>::iterator>
  my_begin(std::vector<cNodeDescriptor*>& v)
  {
       return boost::make_indirect_iterator(v.begin());
  };

  boost::indirect_iterator<std::vector<cNodeDescriptor*>::iterator>
  my_end(std::vector<cNodeDescriptor*>& v)
  {
       return boost::make_indirect_iterator(v.end());
  };

so, something like:

  class_ <std::vector <cNodeDescriptor *> > ("cNodeDescriptorList")
	  .def("__iter__", range(my_begin, my_end))
      ;


HTH,

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com




More information about the Cplusplus-sig mailing list