unique_ptr boost equivalent?

Posted by wowus on Stack Overflow See other posts from Stack Overflow or by wowus
Published on 2010-06-01T21:37:17Z Indexed on 2010/06/01 21:43 UTC
Read the original article Hit count: 295

Filed under:
|
|

Is there some equivalent class for C++1x's std::unique_ptr in the boost libraries? The behavior I'm looking for is being able to have an exception-safe factory function, like so...

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.
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost