¿Hay alguna clase equivalente para C++ 1x std :: unique_ptr en las bibliotecas de impulso? El comportamiento que estoy buscando es ser capaz de tener una función de fábrica excepción de fallos, al igual que ...unique_ptr boost equivalent?
std::unique_ptr<Base> create_base()
{
return std::unique_ptr<Base>(new Derived);
}
void some_other_function()
{
std::unique_ptr<Base> b = create_base();
// Do some stuff with b that may or may not throw an exception...
// Now b is destructed automagically.
}
EDIT: En este momento, estoy usando este truco, que parece que lo mejor que pueda llegar a este punto ...
Base* create_base()
{
return new Derived;
}
void some_other_function()
{
boost::scoped_ptr<Base> b = create_base();
// Do some stuff with b that may or may not throw an exception...
// Now b is deleted automagically.
}
Además, ¿se puede crear este efecto haciendo que el constructor de copia tenga semántica de movimiento, y luego el destructor comprueba antes de liberar? –