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

Unified Diff: third_party/WebKit/Source/wtf/HashSet.h

Issue 1998543003: WTF: Add support for std::initializer_list in HashSet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/HashSetTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/HashSet.h
diff --git a/third_party/WebKit/Source/wtf/HashSet.h b/third_party/WebKit/Source/wtf/HashSet.h
index afd943b3f2936dd10fa69eb8ace109c58fb32f30..865f0da2517f867e11a681918c0cd7db7c6ac228 100644
--- a/third_party/WebKit/Source/wtf/HashSet.h
+++ b/third_party/WebKit/Source/wtf/HashSet.h
@@ -23,6 +23,7 @@
#include "wtf/HashTable.h"
#include "wtf/allocator/PartitionAllocator.h"
+#include <initializer_list>
namespace WTF {
@@ -55,6 +56,15 @@ public:
typedef HashTableConstIteratorAdapter<HashTableType, ValueTraits> const_iterator;
typedef typename HashTableType::AddResult AddResult;
+ HashSet() = default;
+ HashSet(const HashSet&) = default;
+ HashSet& operator=(const HashSet&) = default;
+ HashSet(HashSet&&) = default;
+ HashSet& operator=(HashSet&&) = default;
+
+ HashSet(std::initializer_list<ValueType> elements);
+ HashSet& operator=(std::initializer_list<ValueType> elements);
+
void swap(HashSet& ref)
{
m_impl.swap(ref.m_impl);
@@ -131,6 +141,22 @@ struct HashSetTranslatorAdapter {
}
};
+template <typename Value, typename HashFunctions, typename Traits, typename Allocator>
+HashSet<Value, HashFunctions, Traits, Allocator>::HashSet(std::initializer_list<ValueType> elements)
+{
tzik 2016/05/19 08:59:57 Can we reserveCapacity here?
Yuta Kitamura 2016/05/19 09:04:21 Done.
+ for (const auto& element : elements)
+ add(element);
+}
+
+template <typename Value, typename HashFunctions, typename Traits, typename Allocator>
+auto HashSet<Value, HashFunctions, Traits, Allocator>::operator=(std::initializer_list<ValueType> elements) -> HashSet&
+{
+ clear();
+ for (const auto& element : elements)
+ add(element);
+ return *this;
+}
+
template <typename T, typename U, typename V, typename W>
inline unsigned HashSet<T, U, V, W>::size() const
{
« no previous file with comments | « no previous file | third_party/WebKit/Source/wtf/HashSetTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698