Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: base/memory/scoped_ptr_unittest.cc

Issue 1410703002: RValue emulation magically works in C++11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: With rvalue references Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 #include <vector>
8 9
9 #include "base/basictypes.h" 10 #include "base/basictypes.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace { 15 namespace {
15 16
16 // Used to test depth subtyping. 17 // Used to test depth subtyping.
17 class ConDecLoggerParent { 18 class ConDecLoggerParent {
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 a->b.reset(new StructB); 710 a->b.reset(new StructB);
710 a->b->a.reset(a); 711 a->b->a.reset(a);
711 712
712 // Break the cycle by calling reset(). This will cause |a| (and hence, |a.b|) 713 // Break the cycle by calling reset(). This will cause |a| (and hence, |a.b|)
713 // to be deleted before the call to reset() returns. This tests that the 714 // to be deleted before the call to reset() returns. This tests that the
714 // implementation of scoped_ptr::reset() doesn't access |this| after it 715 // implementation of scoped_ptr::reset() doesn't access |this| after it
715 // deletes the underlying pointer. This behaviour is consistent with the 716 // deletes the underlying pointer. This behaviour is consistent with the
716 // definition of unique_ptr::reset in C++11. 717 // definition of unique_ptr::reset in C++11.
717 a->b.reset(); 718 a->b.reset();
718 } 719 }
720
721 template<typename T>
722 class ScopedPtr2 {
723 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedPtr2)
724 public:
725 explicit ScopedPtr2(T* p) : p_(p) { }
726 ~ScopedPtr2() { delete p_; }
727
728 ScopedPtr2(ScopedPtr2&& rhs) : p_(nullptr) {
729 using std::swap;
730 swap(p_, rhs.p_);
731 }
732
733 ScopedPtr2& operator=(ScopedPtr2&& rhs) {
734 using std::swap;
735 swap(p_, rhs.p_);
736 }
737
738 private:
739 T* p_;
740 };
741
742 TEST(ScopedPtrTest, VectorOfScopedPtrs) {
743 class TestClassPleaseIgnore {
744 };
745 std::vector<ScopedPtr2<TestClassPleaseIgnore>> x;
746 x.push_back(ScopedPtr2<TestClassPleaseIgnore>(new TestClassPleaseIgnore));
747 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698