------- Comment #12 from redi at gcc dot gnu dot org  2010-03-01 22:38 -------
Bear in mind that a custom deleter with custom pointer type might have very
different semantics for comparing pointer values and for invoking the deleter. 
Consider a custom D::pointer which keeps a generation count, which is not used
when comparing for equality:

template<class T>
struct MyDeleter {
  struct pointer {
    int generation;
    T* ptr;
    pointer() : generation(), ptr() { }
    bool operator==(pointer rhs)
    { return ptr == rhs.ptr; }
  };
  void operator()(pointer p) const
  {
    do_something(ptr.generation);
    delete p.ptr;
  }
  void do_something(int gen);
};

Your suggested implementation would not update the value, because the equality
test is true, but that would be wrong i.e. you would have failed to reset the
unique_ptr as requested by the user.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43183

Reply via email to