We’re removing scoped_ptr from Chromium. scoped_ptr is already a typedef for std::unique_ptr, and now we're going to mass-replace scoped_ptr with std::unique_ptr. This will take place over the next few weeks. New code should:
- Use std::unique_ptr instead of scoped_ptr: they work exactly the same
- #include <utility> instead of "base/memory/scoped_ptr.h"
- Use base::WrapUnique() instead of make_scoped_ptr(), which is in base/memory/ptr_util.h.
FAQQ: Are there any gotchas with std::unique_ptr?A: std::unique_ptr behaves exactly the same as scoped_ptr, but one thing to be careful of is accessing a std::unique_ptr (e.g. testing if it’s null) while it is being destroyed: the behavior is undefined [1], and different implementations will do different things.Q: Will std::unique_ptr work with base::Bind and base::Callback?A: Yes, std::unique_ptr can be bound to a callback and passed the same way it is today.std::unique_ptr<int> x(new int(6));base::Closure cb = base::Bind(&TakesInt, base::Passed(&x));Q: Why is make_scoped_ptr’s replacement called base::WrapUnique() instead of base::MakeUnique()?A: C++14 adds a std::make_unique() with different semantics [2]. To avoid confusion, we’ve renamed it to base::WrapUnique() to reflect its functionality of wrapping a raw pointer in a smart pointer.- Daniel, with thanks to danakj, amistry, and everyone who helped make this possible!
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
On Thu, Mar 31, 2016 at 6:57 PM, Daniel Cheng <dch...@chromium.org> wrote:We’re removing scoped_ptr from Chromium. scoped_ptr is already a typedef for std::unique_ptr, and now we're going to mass-replace scoped_ptr with std::unique_ptr. This will take place over the next few weeks. New code should:
- Use std::unique_ptr instead of scoped_ptr: they work exactly the same
- #include <utility> instead of "base/memory/scoped_ptr.h"
Shouldn't this be <memory> instead of <utility>?
Q: Why is make_scoped_ptr’s replacement called base::WrapUnique() instead of base::MakeUnique()?A: C++14 adds a std::make_unique() with different semantics [2]. To avoid confusion, we’ve renamed it to base::WrapUnique() to reflect its functionality of wrapping a raw pointer in a smart pointer.
Wow, I didn't know scoped_ptr had been replaced with a typedef to unique_ptr already. This is like when your parents put healthy food in your normal meals and then after you eat it they say "see! We put healthy food in there and you didn't even notice!" Well done, team.On a more serious note, the mass-replacement of scoped_ptr with std::unique_ptr could be the first candidate for the git hyper-blame ignore list (.git-blame-ignore-revs), so when you run git hyper-blame on some Chromium code you won't be told about the mass-replacement CL.Matt
On Thu, Mar 31, 2016 at 10:32 PM Matt Giuca <mgi...@chromium.org> wrote:Wow, I didn't know scoped_ptr had been replaced with a typedef to unique_ptr already. This is like when your parents put healthy food in your normal meals and then after you eat it they say "see! We put healthy food in there and you didn't even notice!" Well done, team.On a more serious note, the mass-replacement of scoped_ptr with std::unique_ptr could be the first candidate for the git hyper-blame ignore list (.git-blame-ignore-revs), so when you run git hyper-blame on some Chromium code you won't be told about the mass-replacement CL.MattOut of curiosity, how well does hyper-blame scale with the number of commits to ignore? There's some scripts to automate the conversion, but they aren't perfect, so it's still better to break the work into smaller commits.