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

Side by Side Diff: base/memory/scoped_vector.h

Issue 1407443002: Remove old C++03 move emulation code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: std::move and reflow Created 5 years 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 | « base/files/file.cc ('k') | base/move.h » ('j') | 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 #ifndef BASE_MEMORY_SCOPED_VECTOR_H_ 5 #ifndef BASE_MEMORY_SCOPED_VECTOR_H_
6 #define BASE_MEMORY_SCOPED_VECTOR_H_ 6 #define BASE_MEMORY_SCOPED_VECTOR_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/move.h" 13 #include "base/move.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 15
16 // ScopedVector wraps a vector deleting the elements from its 16 // ScopedVector wraps a vector deleting the elements from its
17 // destructor. 17 // destructor.
18 // 18 //
19 // TODO(http://crbug.com/554289): DEPRECATED: Use std::vector instead (now that 19 // TODO(http://crbug.com/554289): DEPRECATED: Use std::vector instead (now that
20 // we have support for moveable types inside containers). 20 // we have support for moveable types inside containers).
21 template <class T> 21 template <class T>
22 class ScopedVector { 22 class ScopedVector {
23 MOVE_ONLY_TYPE_FOR_CPP_03(ScopedVector, RValue) 23 MOVE_ONLY_TYPE_FOR_CPP_03(ScopedVector)
24 24
25 public: 25 public:
26 typedef typename std::vector<T*>::allocator_type allocator_type; 26 typedef typename std::vector<T*>::allocator_type allocator_type;
27 typedef typename std::vector<T*>::size_type size_type; 27 typedef typename std::vector<T*>::size_type size_type;
28 typedef typename std::vector<T*>::difference_type difference_type; 28 typedef typename std::vector<T*>::difference_type difference_type;
29 typedef typename std::vector<T*>::pointer pointer; 29 typedef typename std::vector<T*>::pointer pointer;
30 typedef typename std::vector<T*>::const_pointer const_pointer; 30 typedef typename std::vector<T*>::const_pointer const_pointer;
31 typedef typename std::vector<T*>::reference reference; 31 typedef typename std::vector<T*>::reference reference;
32 typedef typename std::vector<T*>::const_reference const_reference; 32 typedef typename std::vector<T*>::const_reference const_reference;
33 typedef typename std::vector<T*>::value_type value_type; 33 typedef typename std::vector<T*>::value_type value_type;
34 typedef typename std::vector<T*>::iterator iterator; 34 typedef typename std::vector<T*>::iterator iterator;
35 typedef typename std::vector<T*>::const_iterator const_iterator; 35 typedef typename std::vector<T*>::const_iterator const_iterator;
36 typedef typename std::vector<T*>::reverse_iterator reverse_iterator; 36 typedef typename std::vector<T*>::reverse_iterator reverse_iterator;
37 typedef typename std::vector<T*>::const_reverse_iterator 37 typedef typename std::vector<T*>::const_reverse_iterator
38 const_reverse_iterator; 38 const_reverse_iterator;
39 39
40 ScopedVector() {} 40 ScopedVector() {}
41 ~ScopedVector() { clear(); } 41 ~ScopedVector() { clear(); }
42 ScopedVector(RValue other) { swap(*other.object); } 42 ScopedVector(ScopedVector&& other) { swap(other); }
43 43
44 ScopedVector& operator=(RValue rhs) { 44 ScopedVector& operator=(ScopedVector&& rhs) {
45 swap(*rhs.object); 45 swap(rhs);
46 return *this; 46 return *this;
47 } 47 }
48 48
49 reference operator[](size_t index) { return v_[index]; } 49 reference operator[](size_t index) { return v_[index]; }
50 const_reference operator[](size_t index) const { return v_[index]; } 50 const_reference operator[](size_t index) const { return v_[index]; }
51 51
52 bool empty() const { return v_.empty(); } 52 bool empty() const { return v_.empty(); }
53 size_t size() const { return v_.size(); } 53 size_t size() const { return v_.size(); }
54 54
55 reverse_iterator rbegin() { return v_.rbegin(); } 55 reverse_iterator rbegin() { return v_.rbegin(); }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // Like |erase()|, but doesn't delete the elements in [first, last). 137 // Like |erase()|, but doesn't delete the elements in [first, last).
138 iterator weak_erase(iterator first, iterator last) { 138 iterator weak_erase(iterator first, iterator last) {
139 return v_.erase(first, last); 139 return v_.erase(first, last);
140 } 140 }
141 141
142 private: 142 private:
143 std::vector<T*> v_; 143 std::vector<T*> v_;
144 }; 144 };
145 145
146 #endif // BASE_MEMORY_SCOPED_VECTOR_H_ 146 #endif // BASE_MEMORY_SCOPED_VECTOR_H_
OLDNEW
« no previous file with comments | « base/files/file.cc ('k') | base/move.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698