20 typedef QHash<T, QHashDummyValue> Hash;
23 inline QSet()
noexcept {}
24 inline QSet(std::initializer_list<T> list)
25 : QSet(list.begin(), list.end()) {}
26 template <
typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> =
true>
27 inline QSet(InputIterator first, InputIterator last)
29 QtPrivate::reserveIfForwardIterator(
this, first, last);
30 for (; first != last; ++first)
37 inline void swap(QSet<T> &other)
noexcept { q_hash.swap(other.q_hash); }
41 template <
typename U = T, QTypeTraits::compare_eq_result_container<QSet, U> =
true>
42 friend bool comparesEqual(
const QSet &lhs,
const QSet &rhs)
noexcept
44 return lhs.q_hash == rhs.q_hash;
46 QT_DECLARE_EQUALITY_OPERATORS_HELPER(QSet, QSet, ,
noexcept,
47 template <
typename U = T, QTypeTraits::compare_eq_result_container<QSet, U> =
true>)
50 friend bool operator==(
const QSet &lhs,
const QSet &rhs)
noexcept;
51 friend bool operator!=(
const QSet &lhs,
const QSet &rhs)
noexcept;
54 inline qsizetype size()
const {
return q_hash.size(); }
56 inline bool isEmpty()
const {
return q_hash.isEmpty(); }
58 inline qsizetype capacity()
const {
return q_hash.capacity(); }
59 inline void reserve(qsizetype size);
60 inline void squeeze() { q_hash.squeeze(); }
62 inline void detach() { q_hash.detach(); }
63 inline bool isDetached()
const {
return q_hash.isDetached(); }
65 inline void clear() { q_hash.clear(); }
67 inline bool remove(
const T &value) {
return q_hash.remove(value) != 0; }
69 template <
typename Pred>
70 inline qsizetype removeIf(Pred predicate)
72 return QtPrivate::qset_erase_if(*
this, predicate);
75 inline bool contains(
const T &value)
const {
return q_hash.contains(value); }
77 bool contains(
const QSet<T> &set)
const;
83 typedef QHash<T, QHashDummyValue> Hash;
84 typename Hash::iterator i;
85 friend class const_iterator;
89 typedef std::forward_iterator_tag iterator_category;
90 typedef qptrdiff difference_type;
92 typedef const T *pointer;
93 typedef const T &reference;
96 inline iterator(
typename Hash::iterator o) : i(o) {}
97 inline iterator(
const iterator &o) : i(o.i) {}
98 inline iterator &operator=(
const iterator &o) { i = o.i;
return *
this; }
99 inline const T &operator*()
const {
return i.key(); }
100 inline const T *operator->()
const {
return &i.key(); }
101 inline bool operator==(
const iterator &o)
const {
return i == o.i; }
102 inline bool operator!=(
const iterator &o)
const {
return i != o.i; }
103 inline bool operator==(
const const_iterator &o)
const
105 inline bool operator!=(
const const_iterator &o)
const
107 inline iterator &operator++() { ++i;
return *
this; }
108 inline iterator operator++(
int) { iterator r = *
this; ++i;
return r; }
113 typedef QHash<T, QHashDummyValue> Hash;
114 typename Hash::const_iterator i;
115 friend class iterator;
116 friend class QSet<T>;
119 typedef std::forward_iterator_tag iterator_category;
120 typedef qptrdiff difference_type;
121 typedef T value_type;
122 typedef const T *pointer;
123 typedef const T &reference;
125 inline const_iterator() {}
126 inline const_iterator(
typename Hash::const_iterator o) : i(o) {}
127 inline const_iterator(
const const_iterator &o) : i(o.i) {}
128 inline const_iterator(
const iterator &o)
130 inline const_iterator &operator=(
const const_iterator &o) { i = o.i;
return *
this; }
131 inline const T &operator*()
const {
return i.key(); }
132 inline const T *operator->()
const {
return &i.key(); }
133 inline bool operator==(
const const_iterator &o)
const {
return i == o.i; }
134 inline bool operator!=(
const const_iterator &o)
const {
return i != o.i; }
135 inline const_iterator &operator++() { ++i;
return *
this; }
136 inline const_iterator operator++(
int) { const_iterator r = *
this; ++i;
return r; }
140 inline iterator begin() {
return q_hash.begin(); }
141 inline const_iterator begin()
const noexcept {
return q_hash.begin(); }
142 inline const_iterator cbegin()
const noexcept {
return q_hash.begin(); }
143 inline const_iterator constBegin()
const noexcept {
return q_hash.constBegin(); }
144 inline iterator end() {
return q_hash.end(); }
145 inline const_iterator end()
const noexcept {
return q_hash.end(); }
146 inline const_iterator cend()
const noexcept {
return q_hash.end(); }
147 inline const_iterator constEnd()
const noexcept {
return q_hash.constEnd(); }
149 iterator erase(const_iterator i)
151 Q_ASSERT(i != constEnd());
152 return q_hash.erase(i.i);
156 typedef iterator Iterator;
157 typedef const_iterator ConstIterator;
158 inline qsizetype count()
const {
return q_hash.size(); }
159 inline iterator insert(
const T &value)
160 {
return q_hash.insert(value, QHashDummyValue()); }
161 inline iterator insert(T &&value)
162 {
return q_hash.emplace(std::move(value), QHashDummyValue()); }
163 iterator find(
const T &value) {
return q_hash.find(value); }
164 const_iterator find(
const T &value)
const {
return q_hash.find(value); }
165 inline const_iterator constFind(
const T &value)
const {
return find(value); }
166 QSet<T> &unite(
const QSet<T> &other);
167 QSet<T> &intersect(
const QSet<T> &other);
168 bool intersects(
const QSet<T> &other)
const;
169 QSet<T> &subtract(
const QSet<T> &other);
173 typedef T value_type;
174 typedef value_type *pointer;
175 typedef const value_type *const_pointer;
176 typedef value_type &reference;
177 typedef const value_type &const_reference;
178 typedef qptrdiff difference_type;
179 typedef qsizetype size_type;
181 inline bool empty()
const {
return isEmpty(); }
183 iterator insert(const_iterator,
const T &value) {
return insert(value); }
186 inline QSet<T> &operator<<(
const T &value) { insert(value);
return *
this; }
187 inline QSet<T> &operator|=(
const QSet<T> &other) { unite(other);
return *
this; }
188 inline QSet<T> &operator|=(
const T &value) { insert(value);
return *
this; }
189 inline QSet<T> &operator&=(
const QSet<T> &other) { intersect(other);
return *
this; }
190 inline QSet<T> &operator&=(
const T &value)
191 { QSet<T> result;
if (contains(value)) result.insert(value);
return (*
this = result); }
192 inline QSet<T> &operator+=(
const QSet<T> &other) { unite(other);
return *
this; }
193 inline QSet<T> &operator+=(
const T &value) { insert(value);
return *
this; }
194 inline QSet<T> &operator-=(
const QSet<T> &other) { subtract(other);
return *
this; }
195 inline QSet<T> &operator-=(
const T &value) { remove(value);
return *
this; }
197 friend QSet operator|(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) |= rhs; }
198 friend QSet operator|(QSet &&lhs,
const QSet &rhs) { lhs |= rhs;
return std::move(lhs); }
200 friend QSet operator&(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) &= rhs; }
201 friend QSet operator&(QSet &&lhs,
const QSet &rhs) { lhs &= rhs;
return std::move(lhs); }
203 friend QSet operator+(
const QSet &lhs,
const QSet &rhs) {
return QSet(lhs) += rhs; }
204 friend QSet operator+(QSet &&lhs,
const QSet &rhs) { lhs += rhs;
return std::move(lhs); }
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 QList<T> values()
const;