We use boost::scoped_ptr everywhere to handle scope-owned heap-allocated
objects. C++11 has std::unique_ptr for this. I'd like to get a decision on
whether we should start standardising on unique_ptr. This is particularly
relevant for new code - should I call it out in code review?

The most significant difference is that unique_ptr is moveable, which means
it can be used in collections (good!). It also means that badly written
code can allow scope-owned objects to escape their scope:

private:
  unique_ptr<Foo> foo_;

public:
  unique_ptr<Foo> get_foo() { return move(foo_); }

or worse:

  Foo* get_foo() { return foo_.release(); }

In both cases you have to be quite explicit about the decision to yield
ownership of the owned object, and it seems to me that we should catch this
in code review.

Since using unique_ptr in collections is so useful, and reducing our boost
dependency is generally worthwhile, I'm very much in favour of moving to
unique_ptr for future code, and at some point porting all the current
scoped_ptr to unique_ptr.

What do you think?

Henry

Reply via email to