mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-06 09:44:39 +00:00
[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:
parent
01394fb9e4
commit
b6193185a0
@ -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 {
|
||||
|
@ -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();
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user