Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/HashMap.h |
| diff --git a/third_party/WebKit/Source/wtf/HashMap.h b/third_party/WebKit/Source/wtf/HashMap.h |
| index 3ac16620a3a1ed34715764bf689032fc8d29d46e..f81c66f413dd29a0046b005191a1853d58a188ea 100644 |
| --- a/third_party/WebKit/Source/wtf/HashMap.h |
| +++ b/third_party/WebKit/Source/wtf/HashMap.h |
| @@ -23,6 +23,7 @@ |
| #include "wtf/HashTable.h" |
| #include "wtf/allocator/PartitionAllocator.h" |
| +#include <initializer_list> |
| namespace WTF { |
| @@ -88,6 +89,15 @@ class HashMap { |
| "Cannot put raw pointers to garbage-collected classes into " |
| "an off-heap HashMap. Use HeapHashMap<> instead."); |
| } |
| + HashMap(const HashMap&) = default; |
| + HashMap& operator=(const HashMap&) = default; |
| + HashMap(HashMap&&) = default; |
| + HashMap& operator=(HashMap&&) = default; |
| + |
| + // For example, HashMap<int, int>({{1, 11}, {2, 22}, {3, 33}}) will give you |
| + // a HashMap containing a mapping {1 -> 11, 2 -> 22, 3 -> 33}. |
| + HashMap(std::initializer_list<ValueType> elements); |
| + HashMap& operator=(std::initializer_list<ValueType> elements); |
| typedef HashTableIteratorAdapter<HashTableType, ValueType> iterator; |
| typedef HashTableConstIteratorAdapter<HashTableType, ValueType> |
| @@ -336,6 +346,31 @@ template <typename T, |
| typename W, |
| typename X, |
| typename Y> |
| +HashMap<T, U, V, W, X, Y>::HashMap(std::initializer_list<ValueType> elements) { |
| + if (elements.size()) |
| + m_impl.reserveCapacityForSize(elements.size()); |
| + for (const ValueType& element : elements) |
| + add(element.key, element.value); |
|
tzik
2017/01/18 13:36:40
Can we std::move() them?
Yuta Kitamura
2017/01/19 06:07:04
No, because std::initializer_list<T>::reference is
Yuta Kitamura
2017/01/19 06:08:08
typo: ValueType&& -> ValueType&.
|
| +} |
| + |
| +template <typename T, |
| + typename U, |
| + typename V, |
| + typename W, |
| + typename X, |
| + typename Y> |
| +auto HashMap<T, U, V, W, X, Y>::operator=( |
| + std::initializer_list<ValueType> elements) -> HashMap& { |
| + *this = HashMap(std::move(elements)); |
| + return *this; |
| +} |
| + |
| +template <typename T, |
| + typename U, |
| + typename V, |
| + typename W, |
| + typename X, |
| + typename Y> |
| inline unsigned HashMap<T, U, V, W, X, Y>::size() const { |
| return m_impl.size(); |
| } |