ブースト ライブラリに C++1x の std::unique_ptr に相当するクラスはありますか? 私が探している動作は、例外セーフなファクトリ関数を持つことができることです...
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.
}
編集:現在、私はこのハックを使用しています。これは、現時点で入手できる最高のようです...
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.
}