[C++11] Add release() to OwningPtr.

This will make the transition to unique_ptr easier by allowing more
incremental changes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202949 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Ahmed Charles 2014-03-05 08:25:08 +00:00
parent 01394fb9e4
commit b6193185a0
2 changed files with 20 additions and 0 deletions

View File

@ -73,6 +73,8 @@ public:
return Tmp;
}
T *release() { return take(); }
std::unique_ptr<T> take_unique() { return std::unique_ptr<T>(take()); }
T &operator*() const {

View File

@ -90,6 +90,24 @@ TEST_F(OwningPtrTest, Take) {
EXPECT_EQ(1u, TrackDestructor::Destructions);
}
TEST_F(OwningPtrTest, Release) {
TrackDestructor::ResetCounts();
TrackDestructor *T = 0;
{
OwningPtr<TrackDestructor> O(new TrackDestructor(3));
T = O.release();
EXPECT_FALSE((bool)O);
EXPECT_TRUE(!O);
EXPECT_FALSE(O.get());
EXPECT_FALSE(O.isValid());
EXPECT_TRUE(T);
EXPECT_EQ(3, T->val);
EXPECT_EQ(0u, TrackDestructor::Destructions);
}
delete T;
EXPECT_EQ(1u, TrackDestructor::Destructions);
}
TEST_F(OwningPtrTest, MoveConstruction) {
TrackDestructor::ResetCounts();
{