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

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: Simplify assignment. 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..4f36cf224797de40319a0b813f11f24c979eeffb 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)
+{
+ if (elements.size())
+ m_impl.reserveCapacityForSize(elements.size());
+ for (const ValueType& 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&
+{
+ *this = HashSet(std::move(elements));
+ 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