21 typedef QHash<T, QHashDummyValue> Hash;
24 inline QSet()
noexcept {}
25 inline QSet(std::initializer_list<T> list)
26 : QSet(list.begin(), list.end()) {}
27 template <
typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> =
true>
28 inline QSet(InputIterator first, InputIterator last)
30 QtPrivate::reserveIfForwardIterator(
this, first, last);
31 for (; first != last; ++first)
38 inline void swap(QSet<T> &other)
noexcept { q_hash.swap(other.q_hash); }
42 template <
typename U = T, QTypeTraits::compare_eq_result_container<QSet, U> =
true>
43 friend bool comparesEqual(
const QSet &lhs,
const QSet &rhs)
noexcept
45 return lhs.q_hash == rhs.q_hash;
47 QT_DECLARE_EQUALITY_OPERATORS_HELPER(QSet, QSet, ,
noexcept,
48 template <
typename U = T, QTypeTraits::compare_eq_result_container<QSet, U> =
true>)
51 friend bool operator==(
const QSet &lhs,
const QSet &rhs)
noexcept;
52 friend bool operator!=(
const QSet &lhs,
const QSet &rhs)
noexcept;
55 inline qsizetype size()
const {
return q_hash.size(); }
57 inline bool isEmpty()
const {
return q_hash.isEmpty(); }
59 inline qsizetype capacity()
const {
return q_hash.capacity(); }
60 inline void reserve(qsizetype size);
61 inline void squeeze() { q_hash.squeeze(); }
63 inline void detach() { q_hash.detach(); }
64 inline bool isDetached()
const {
return q_hash.isDetached(); }
66 inline void clear() { q_hash.clear(); }
68 bool remove(
const T &value) {
return q_hash.remove(value); }
70 template <
typename Pred>
71 inline qsizetype removeIf(Pred predicate)
73 return QtPrivate::qset_erase_if(*
this, predicate);
76 inline bool contains(
const T &value)
const {
return q_hash.contains(value); }
78 bool contains(
const QSet<T> &set)
const;
84 typedef QHash<T, QHashDummyValue> Hash;
85 typename Hash::iterator i;
86 friend class const_iterator;
90 typedef std::forward_iterator_tag iterator_category;
91 typedef qptrdiff difference_type;
93 typedef const T *pointer;
94 typedef const T &reference;
97 inline iterator(
typename Hash::iterator o) : i(o) {}
98 inline iterator(
const iterator &o) : i(o.i) {}
99 inline iterator &operator=(
const iterator &o) { i = o.i;
return *
this; }
100 inline const T &operator*()
const {
return i.key(); }
101 inline const T *operator->()
const {
return &i.key(); }
102 inline bool operator==(
const iterator &o)
const {
return i == o.i; }
103 inline bool operator!=(
const iterator &o)
const {
return i != o.i; }
104 inline bool operator==(
const const_iterator &o)
const
106 inline bool operator!=(
const const_iterator &o)
const
108 inline iterator &operator++() { ++i;
return *
this; }
109 inline iterator operator++(
int) { iterator r = *
this; ++i;
return r; }
114 typedef QHash<T, QHashDummyValue> Hash;
115 typename Hash::const_iterator i;
116 friend class iterator;
117 friend class QSet<T>;
120 typedef std::forward_iterator_tag iterator_category;
121 typedef qptrdiff difference_type;
122 typedef T value_type;
123 typedef const T *pointer;
124 typedef const T &reference;
126 inline const_iterator() {}
127 inline const_iterator(
typename Hash::const_iterator o) : i(o) {}
128 inline const_iterator(
const const_iterator &o) : i(o.i) {}
129 inline const_iterator(
const iterator &o)
131 inline const_iterator &operator=(
const const_iterator &o) { i = o.i;
return *
this; }
132 inline const T &operator*()
const {
return i.key(); }
133 inline const T *operator->()
const {
return &i.key(); }
134 inline bool operator==(
const const_iterator &o)
const {
return i == o.i; }
135 inline bool operator!=(
const const_iterator &o)
const {
return i != o.i; }
136 inline const_iterator &operator++() { ++i;
return *
this; }
137 inline const_iterator operator++(
int) { const_iterator r = *
this; ++i;
return r; }
141 inline iterator begin() {
return q_hash.begin(); }
142 inline const_iterator begin()
const noexcept {
return q_hash.begin(); }
143 inline const_iterator cbegin()
const noexcept {
return q_hash.begin(); }
144 inline const_iterator constBegin()
const noexcept {
return q_hash.constBegin(); }
145 inline iterator end() {
return q_hash.end(); }
146 inline const_iterator end()
const noexcept {
return q_hash.end(); }
147 inline const_iterator cend()
const noexcept {
return q_hash.end(); }
148 inline const_iterator constEnd()
const noexcept {
return q_hash.constEnd(); }
150 iterator erase(const_iterator i)
152 Q_ASSERT(i != constEnd());
153 return q_hash.erase(i.i);
157 typedef iterator Iterator;
158 typedef const_iterator ConstIterator;
159 inline qsizetype count()
const {
return q_hash.size(); }
160 inline iterator insert(
const T &value)
161 {
return q_hash.insert(value, QHashDummyValue()); }
162 inline iterator insert(T &&value)
163 {
return q_hash.emplace(std::move(value), QHashDummyValue()); }
164 iterator find(
const T &value) {
return q_hash.find(value); }
165 const_iterator find(
const T &value)
const {
return q_hash.find(value); }
166 inline const_iterator constFind(
const T &value)
const {
return find(value); }
167 QSet<T> &unite(
const QSet<T> &other);
168 QSet &unite(QSet &&other);
169 QSet<T> &intersect(
const QSet<T> &other);
170 bool intersects(
const QSet<T> &other)
const;
171 QSet<T> &subtract(
const QSet<T> &other);
175 typedef T value_type;
176 typedef value_type *pointer;
177 typedef const value_type *const_pointer;
178 typedef value_type &reference;
179 typedef const value_type &const_reference;
180 typedef qptrdiff difference_type;
181 typedef qsizetype size_type;
183 inline bool empty()
const {
return isEmpty(); }
185 iterator insert(const_iterator,
const T &value) {
return insert(value); }
188 inline QSet<T> &operator<<(
const T &value) { insert(value);
return *
this; }
189 inline QSet<T> &operator|=(
const QSet<T> &other) { unite(other);
return *
this; }
190 QSet &operator|=(QSet &&other) {
return unite(std::move(other)); }
191 inline QSet<T> &operator|=(
const T &value) { insert(value);
return *
this; }
192 inline QSet<T> &operator&=(
const QSet<T> &other) { intersect(other);
return *
this; }
193 inline QSet<T> &operator&=(
const T &value)
194 { QSet<T> result;
if (contains(value)) result.insert(value);
return (*
this = result); }
195 inline QSet<T> &operator+=(
const QSet<T> &other) { unite(other);
return *
this; }
196 QSet &operator+=(QSet &&other) {
return unite(std::move(other)); }
197 inline QSet<T> &operator+=(
const T &value) { insert(value);
return *
this; }
198 inline QSet<T> &operator-=(
const QSet<T> &other) { subtract(other);
return *
this; }
199 inline QSet<T> &operator-=(
const T &value) { remove(value);
return *
this; }
201 friend QSet operator|(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) |= rhs; }
202 friend QSet operator|(QSet &&lhs,
const QSet &rhs) { lhs |= rhs;
return std::move(lhs); }
203 friend QSet operator|(
const QSet &lhs, QSet &&rhs) {
return lhs |= std::move(rhs); }
204 friend QSet operator|(QSet &&lhs, QSet &&rhs) {
return std::move(lhs) |= std::move(rhs); }
206 friend QSet operator&(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) &= rhs; }
207 friend QSet operator&(QSet &&lhs,
const QSet &rhs) { lhs &= rhs;
return std::move(lhs); }
209 friend QSet operator+(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) += rhs; }
210 friend QSet operator+(QSet &&lhs,
const QSet &rhs) { lhs += rhs;
return std::move(lhs); }
211 friend QSet operator+(
const QSet &lhs, QSet &&rhs) {
return QSet(lhs) += std::move(rhs); }
212 friend QSet operator+(QSet &&lhs, QSet &&rhs) {
return std::move(lhs) += std::move(rhs); }
214 friend QSet operator-(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) -= rhs; }
215 friend QSet operator-(QSet &&lhs,
const QSet &rhs) { lhs -= rhs;
return std::move(lhs); }
217 inline QList<T> values()
const;
220 static inline QSet intersected_helper(
const QSet &lhs,
const QSet &rhs);
222 template <
typename E>
223 void _emplace_or_overwrite(E &&e);