[C++-sig] [boost.python] How can I wrap operator==?

Hans Meine hans_meine at gmx.net
Wed Jan 13 13:54:24 CET 2010


On Mittwoch 13 Januar 2010, Roman Yakovenko wrote:
> On Wed, Jan 13, 2010 at 8:57 AM, blp330 <blp330 at msn.com> wrote:
> > class Document
> > {
> > public:
> >  ....
> >
> >  bool operator==(const Document& other) const
> >  {
> >  return Compare(other);
> >  }
> [...]
> If I understand you right, you need:
>
> 1. define new global function, which takes Document& as the first argument
>
> bool Document_EqualWrap( const Document& x, const Document& y ){...}

Not necessary AFAIK, a member function should work, too.
(i.e. directly exposing &Document::operator==)

> 2. Expose it:
>
> ...
> .def( "__eq__", &Document_EqualWrap )
>
> Is not the working code, but it should give you a direction.

Yes, I think that's what he was missing.

-- 
Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20100113/9ac1e4c6/attachment-0001.pgp>


More information about the Cplusplus-sig mailing list