[C++-sig] Re: iter(std::map<K*,V>)

Mike Rovner mike at bindkey.com
Wed Jun 18 21:21:40 CEST 2003


Thanks a lot, David, this works like a charm.

"David Abrahams" <dave at boost-consulting.com> wrote in message
news:u3ci75yh8.fsf at boost-consulting.com...
> "Mike Rovner" <mike at bindkey.com> writes:
>
> Well, to_python_value is the wrong thing there, unless you want the
> stds::pair<Key*,Value> referenced by the iterator to be copied into a
> new Python object.  I don't think you've wrapped
> std::pair<Key*,Value> have you?

Nope.

> http://www.boost.org/libs/python/doc/v2/ResultConverter.html
> describes the requirements for apply<T>::type.  Its convertible()
> function should return true and its function-call operator should
> produce a PyObject* (owned reference).  Something like
>
>         PyObject* operator()(std::pair<KeyType*,Value> const& x) const
>         {
>             return python::incref(
>                 python::object(ptr(x.first)).ptr()
>             );
>         }
>
> ought to work.

My code:

namespace boost { namespace python {
  struct copy_map_key_ptr
  {
    template <class T>
    struct apply
    {
      typedef Map::value_type result_converter;
      struct type
      {
        bool convertible() const {return true;}
        PyObject* operator()(Map::value_type p) const
          { return incref(object(ptr(p.first)).ptr()); }
        typedef PyObject* result_type;
      };
    };
  };
}}

Mike







More information about the Cplusplus-sig mailing list