List:MySQL++« Previous MessageNext Message »
From:Joseph Artsimovich Date:November 29 2007 12:21pm
Subject:Re: Eyeballs needed on new reference counted pointer template
View as plain text  
>> * Added a no-throwing swap operation. 
>
> Is there a good reason for this to be public?  Isn't it just an
> implementation detail for assign()?
>
>> (Should probably define a global
>> swap(x, y) to use this member)
>
> Why?
>
I am not the original poster, but I can explain that.  The global swap()
function is usually created so that template code such as std::sort()
would use class-specific swap() implementation, rather than a generic
one.  One reason to have a public swap() method is to use it from a
global swap().  Another reason is exception safety.  Often you can't
make your own class exception-safe if it contains members that don't
provide swap().

>     RefCountedPointer<Foo> bar(new Foo);
>     delete bar;
>
> But *really*.  If one is so intent on shooting oneself in the foot....
>
I agree.  I've been using implicit conversion to void* or even T* for a
long time, and I've never accidently used delete on a smart pointer. 
Actually, well written code has very few explicit delete calls, so it's
hard to make a mistake there.

Regards,
    Joseph Artsimovich
Thread
Re: Eyeballs needed on new reference counted pointer templateWarren Young29 Nov
  • Re: Eyeballs needed on new reference counted pointer templateJoseph Artsimovich29 Nov
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young29 Nov
      • Re: Eyeballs needed on new reference counted pointer templateJonathan Wakely30 Nov
        • Re: Eyeballs needed on new reference counted pointer templateWarren Young1 Dec
  • Re: Eyeballs needed on new reference counted pointer templateJonathan Wakely30 Nov
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young1 Dec
  • Re: Eyeballs needed on new reference counted pointer templateJonathan Wakely30 Nov
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young1 Dec