OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 ContiguousContainer_h | 5 #ifndef ContiguousContainer_h |
6 #define ContiguousContainer_h | 6 #define ContiguousContainer_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "wtf/Alignment.h" | 9 #include "wtf/Alignment.h" |
10 #include "wtf/Allocator.h" | 10 #include "wtf/Allocator.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 BaseElementType& first() { return *begin(); } | 139 BaseElementType& first() { return *begin(); } |
140 const BaseElementType& first() const { return *begin(); } | 140 const BaseElementType& first() const { return *begin(); } |
141 BaseElementType& last() { return *rbegin(); } | 141 BaseElementType& last() { return *rbegin(); } |
142 const BaseElementType& last() const { return *rbegin(); } | 142 const BaseElementType& last() const { return *rbegin(); } |
143 BaseElementType& operator[](size_t index) { return *(begin() + index); } | 143 BaseElementType& operator[](size_t index) { return *(begin() + index); } |
144 const BaseElementType& operator[](size_t index) const { return *(begin() + i
ndex); } | 144 const BaseElementType& operator[](size_t index) const { return *(begin() + i
ndex); } |
145 | 145 |
146 template <class DerivedElementType, typename... Args> | 146 template <class DerivedElementType, typename... Args> |
147 DerivedElementType& allocateAndConstruct(Args&&... args) | 147 DerivedElementType& allocateAndConstruct(Args&&... args) |
148 { | 148 { |
149 static_assert(WTF::IsSubclass<DerivedElementType, BaseElementType>::valu
e, | 149 static_assert(std::is_base_of<BaseElementType, DerivedElementType>::valu
e, |
150 "Must use subclass of BaseElementType."); | 150 "Must use subclass of BaseElementType."); |
151 static_assert(alignment % WTF_ALIGN_OF(DerivedElementType) == 0, | 151 static_assert(alignment % WTF_ALIGN_OF(DerivedElementType) == 0, |
152 "Derived type requires stronger alignment."); | 152 "Derived type requires stronger alignment."); |
153 size_t allocSize = align(sizeof(DerivedElementType)); | 153 size_t allocSize = align(sizeof(DerivedElementType)); |
154 return *new (allocate(allocSize, WTF_HEAP_PROFILER_TYPE_NAME(DerivedElem
entType))) DerivedElementType(WTF::forward<Args>(args)...); | 154 return *new (allocate(allocSize, WTF_HEAP_PROFILER_TYPE_NAME(DerivedElem
entType))) DerivedElementType(WTF::forward<Args>(args)...); |
155 } | 155 } |
156 | 156 |
157 void removeLast() | 157 void removeLast() |
158 { | 158 { |
159 ASSERT(!isEmpty()); | 159 ASSERT(!isEmpty()); |
(...skipping 30 matching lines...) Expand all Loading... |
190 ASSERT(alignedSize % alignment == 0); | 190 ASSERT(alignedSize % alignment == 0); |
191 ASSERT(alignedSize >= size); | 191 ASSERT(alignedSize >= size); |
192 ASSERT(alignedSize < size + alignment); | 192 ASSERT(alignedSize < size + alignment); |
193 return alignedSize; | 193 return alignedSize; |
194 } | 194 } |
195 }; | 195 }; |
196 | 196 |
197 } // namespace blink | 197 } // namespace blink |
198 | 198 |
199 #endif // ContiguousContainer_h | 199 #endif // ContiguousContainer_h |
OLD | NEW |