Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 33,163 of 33,346    |
|    Seungbeom Kim to Greg Marr    |
|    Re: Does std::unique_ptr support self-re    |
|    10 Aug 13 05:05:21    |
   
   From: musiphil@bawi.org   
      
   On 2013-08-07 20:28, Greg Marr wrote:   
   > On Wednesday, August 7, 2013 4:40:02 PM UTC-4, Seungbeom Kim wrote:   
   >> Does std::unique_ptr support self-reset? I.e. for a std::unique_ptr   
   >> object u, is the behavior of u.reset(u.get()) well-defined?   
   >   
   > At least in VS2010 and 2012, unique_ptr::reset checks for setting   
   > the same pointer and ignores it.   
      
   I'm curious if that is the behavior guaranteed by the standard.   
   As I understand it, the standard seems to guarantee the opposite:   
   it says get_deleter()(old_p) is called if old_p != nullptr, and   
   in case of a self-reset of a non-null unique_ptr, old_p != nullptr   
   holds and get_deleter()(old_p) should be called. It doesn't say   
   that get_deleter()(old_p) is not called if old_p == p, in contrast   
   to the auto_ptr case where it says "If get() != p then delete get()."   
      
   >> (As a side question, a call to get_deleter() "destorying *this" is   
   >> mentioned twice, but how could get_deleter() destroy *this, since   
   >> it is supposed to delete a unique_ptr::element_type object, not   
   >> a unique_ptr object?)   
   >   
   > It's possible if the element_type contains a unique_ptr.   
   >   
   > struct bad_idea   
   > {   
   > unique_ptr
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca