This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/43183] std::unique_ptr::reset() does not conform to N3035.



------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]