Boost logo

Boost :

From: Sylvester-Bradley, Gareth (Gareth.Sylvester-Bradley_at_[hidden])
Date: 2008-07-17 07:48:13


(Apologies for not posting my previous question in plain-text.)

Bind can be used with weak_ptr values, but should function_equal work
with binds holding weak_ptrs?

Since weak_ptr doesn't have operator==, the following results in a
compiler error:

#include <boost/function_equal.hpp>
#include <boost/bind.hpp>
#include <boost/weak_ptr.hpp>

int h( boost::weak_ptr<void> wp ) { return wp.use_count(); }

template < typename F > bool self_equal( F f_ )
{
  return function_equal( f_, f_ );
}

int main( int argc, char * const argv[] )
{
  self_equal( boost::bind( h, _1 ) ); // OK
  self_equal( boost::bind( h, boost::weak_ptr<void>() ) ); // compiler
error
  return 0;
}

Would it be appropriate to use operator< equivalence?

I suspect the answer may be "it depends...", but I made the above
compile by adding the following:

namespace boost
{
  namespace _bi
  {
    template<class T> class value< weak_ptr<T> >
    {
    public:
      value(weak_ptr<T> const & t): t_(t) {}
      
      weak_ptr<T> & get() { return t_; }
      weak_ptr<T> const & get() const { return t_; }
      
      bool operator==(value const & rhs) const
      {
        return !(t_ < rhs.t_) && !(rhs.t_ < t_);
      }
      
    private:
      weak_ptr<T> t_;
    };
  }
}

Is that a good or bad idea?

Thanks,
Gareth

************************************************************************
The information contained in this message or any of its attachments may be confidential and is intended for the exclusive use of the addressee(s). Any disclosure, reproduction, distribution or other dissemination or use of this communication is strictly prohibited without the express permission of the sender. The views expressed in this email are those of the individual and not necessarily those of Sony or Sony affiliated companies. Sony email is for business use only.

This email and any response may be monitored by Sony to be in compliance with Sony's global policies and standards


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk