Talk:More C++ Idioms/Const auto ptr

I tried to translate this page into Japanese and found 3 clarification points.


 * warning and/or error?

"Compiler issues a warning here because the copy-constructor of yptr is not really a copy-constructor but in fact it is a move constructor, which takes a non-const reference to an auto_ptr, as given in Move Constructor idiom. A non-const reference can't bind with a const variable and therefore, compiler flags an error."

I'm confused when reading these sentences. Do the 2 sentences say the same thing or different things? According to my understandings, this produces compilation error.


 * a const RHS as a parameter

"An undesirable consequence of const auto_ptr idiom is that compiler can't provide a default copy-constructor to a class that has a const auto_ptr member in it. This is because the compiler generated copy-constructor always takes a const RHS as a parameter, which can't bind with a non-const move constructor of auto_ptr."

Does "a const RHS as a parameter" mean x.xptr in the below code?


 * Intention of solutions

The subsequent sentence said:

"The solution is to use Virtual Constructor idiom or use boost::scoped_ptr, which explicitly prohibits copying by denying access to assignment and copy-constructor."

By using Virtual Constructor, a class that has a const auto_ptr member in it becomes copyable. However, explicitly defined copy constructor also makes the class copyable, doesn't it?

Furthermore, as described, boost::scoped_ptr explicitly prohibits copy and assignment. Threfore, the situation that the class is not copyable is not changed. Does the sentence mean using boost::scoped_ptr make the intention of prohibition of copy and assignment clearer?

Yak! (talk) 14:48, 15 April 2008 (UTC)

Still useful
A lot of this is still relevant, but now called const std::unique_ptr.