[C++-sig] A vector of objects with private == operators

Matthew Scouten matthew.scouten at gmail.com
Thu Mar 27 17:12:23 CET 2008


Thank you,
This looks like it will fix my problems.
However, the PYTHON_ERROR line will not compile because there is apparently
no such function. Is this a macro specific to your project? if so, what is
behind it?

2008/3/26 Andreas Klöckner <lists at informa.tiker.net>:

> On Mittwoch 26 März 2008, Matthew Scouten wrote:
> > I have noticed that the vector indexing suite only compiles for a
> > vector<foo> if foo has an == operator. Some of the objects that I need
> to
> > wrap in a library have to wrap have no == operator. That's fine, I just
> > create a dummy operator as a global function. The dummy operator just
> tests
> > &a==&b.
> >
> > Now I come to a problem. the 'bar' class has a == operator, but it is
> > declared private. I tried to create a global == operator but the
> compiler
> > complained that it was ambiguous (the compiler is such a whiny little
> > brat.)
> >
> > So my questions are 3 fold,
> > Why the heck does  vector_indexing_suite need an == operator?
> > Assuming I can't change the problem class, what are possible
> workarounds?
> > Does vector_indexing_suite2 still need an == operator?
>
> This is a hack I've been using:
>
> 8< --------------------------------------------------------------
> template <class T>
> class no_compare_indexing_suite :
>  public boost::python::vector_indexing_suite<T, false,
> no_compare_indexing_suite<T> >
> {
>  public:
>    static bool contains(T &container, typename T::value_type const &key)
>    { PYTHON_ERROR(NotImplementedError, "containment checking not supported
> on
> this container"); }
> };
> 8< --------------------------------------------------------------
>
> Use like so:
>
> cl.def(no_compare_indexing_suite<container_type>())
>
> Andreas
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080327/15e2dd75/attachment.htm>


More information about the Cplusplus-sig mailing list