7 Aug 2008 redi   » (Journeyer)

The answer to my C++0x quiz is that the explicitly-specified template argument means that these swap() overloads are tried:


void
swap<A>(shared_ptr<A>&, shared_ptr<A>&);
 
void
swap<A>(shared_ptr<A>&&, shared_ptr<A>&);
 
void
swap<A>(shared_ptr<A>&, shared_ptr<A>&&);

pb doesn't match any of those types, but if a temporary shared_ptr<A> (pointing to the A subobject of *pb) is created from pb, that temporary then binds to the rvalue-reference in the the third swap() overload. So pa is swapped with a temporary, and both pa and pb end up pointing to the same object; swap has performed an assignment!

The solution proposed by Howard Hinnant an hour ago is simply to remove the new swap() overloads from the working paper. The original motivation for them came from n1690, but now that we have std::vector::shrink_to_fit() there's no need for the overloads. So I won't bother adding them to libstdc++.

cdfrey, you may remove your suspenders ;-)

Latest blog entries     Older blog entries

New Advogato Features

FOAF updates: Trust rankings are now exported, making the data available to other users and websites. An external FOAF URI has been added, allowing users to link to an additional FOAF file.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!