@@ -75,37 +75,39 @@ class DenseMapBase : public DebugEpochBase {
75
75
using const_iterator =
76
76
DenseMapIterator<KeyT, ValueT, KeyInfoT, BucketT, true >;
77
77
78
- inline iterator begin () {
78
+ [[nodiscard]] inline iterator begin () {
79
79
return iterator::makeBegin (buckets (), empty (), *this );
80
80
}
81
- inline iterator end () { return iterator::makeEnd (buckets (), *this ); }
82
- inline const_iterator begin () const {
81
+ [[nodiscard]] inline iterator end () {
82
+ return iterator::makeEnd (buckets (), *this );
83
+ }
84
+ [[nodiscard]] inline const_iterator begin () const {
83
85
return const_iterator::makeBegin (buckets (), empty (), *this );
84
86
}
85
- inline const_iterator end () const {
87
+ [[nodiscard]] inline const_iterator end () const {
86
88
return const_iterator::makeEnd (buckets (), *this );
87
89
}
88
90
89
91
// Return an iterator to iterate over keys in the map.
90
- inline auto keys () {
92
+ [[nodiscard]] inline auto keys () {
91
93
return map_range (*this , [](const BucketT &P) { return P.getFirst (); });
92
94
}
93
95
94
96
// Return an iterator to iterate over values in the map.
95
- inline auto values () {
97
+ [[nodiscard]] inline auto values () {
96
98
return map_range (*this , [](const BucketT &P) { return P.getSecond (); });
97
99
}
98
100
99
- inline auto keys () const {
101
+ [[nodiscard]] inline auto keys () const {
100
102
return map_range (*this , [](const BucketT &P) { return P.getFirst (); });
101
103
}
102
104
103
- inline auto values () const {
105
+ [[nodiscard]] inline auto values () const {
104
106
return map_range (*this , [](const BucketT &P) { return P.getSecond (); });
105
107
}
106
108
107
109
[[nodiscard]] bool empty () const { return getNumEntries () == 0 ; }
108
- unsigned size () const { return getNumEntries (); }
110
+ [[nodiscard]] unsigned size () const { return getNumEntries (); }
109
111
110
112
// / Grow the densemap so that it can contain at least \p NumEntries items
111
113
// / before resizing again.
@@ -153,38 +155,43 @@ class DenseMapBase : public DebugEpochBase {
153
155
}
154
156
155
157
// / Return true if the specified key is in the map, false otherwise.
156
- bool contains (const_arg_type_t <KeyT> Val) const {
158
+ [[nodiscard]] bool contains (const_arg_type_t <KeyT> Val) const {
157
159
return doFind (Val) != nullptr ;
158
160
}
159
161
160
162
// / Return 1 if the specified key is in the map, 0 otherwise.
161
- size_type count (const_arg_type_t <KeyT> Val) const {
163
+ [[nodiscard]] size_type count (const_arg_type_t <KeyT> Val) const {
162
164
return contains (Val) ? 1 : 0 ;
163
165
}
164
166
165
- iterator find (const_arg_type_t <KeyT> Val) { return find_as (Val); }
166
- const_iterator find (const_arg_type_t <KeyT> Val) const { return find_as (Val); }
167
+ [[nodiscard]] iterator find (const_arg_type_t <KeyT> Val) {
168
+ return find_as (Val);
169
+ }
170
+ [[nodiscard]] const_iterator find (const_arg_type_t <KeyT> Val) const {
171
+ return find_as (Val);
172
+ }
167
173
168
174
// / Alternate version of find() which allows a different, and possibly
169
175
// / less expensive, key type.
170
176
// / The DenseMapInfo is responsible for supplying methods
171
177
// / getHashValue(LookupKeyT) and isEqual(LookupKeyT, KeyT) for each key
172
178
// / type used.
173
- template <class LookupKeyT > iterator find_as (const LookupKeyT &Val) {
179
+ template <class LookupKeyT >
180
+ [[nodiscard]] iterator find_as (const LookupKeyT &Val) {
174
181
if (BucketT *Bucket = doFind (Val))
175
182
return makeIterator (Bucket);
176
183
return end ();
177
184
}
178
185
template <class LookupKeyT >
179
- const_iterator find_as (const LookupKeyT &Val) const {
186
+ [[nodiscard]] const_iterator find_as (const LookupKeyT &Val) const {
180
187
if (const BucketT *Bucket = doFind (Val))
181
188
return makeConstIterator (Bucket);
182
189
return end ();
183
190
}
184
191
185
192
// / lookup - Return the entry for the specified key, or a default
186
193
// / constructed value if no such entry exists.
187
- ValueT lookup (const_arg_type_t <KeyT> Val) const {
194
+ [[nodiscard]] ValueT lookup (const_arg_type_t <KeyT> Val) const {
188
195
if (const BucketT *Bucket = doFind (Val))
189
196
return Bucket->getSecond ();
190
197
return ValueT ();
@@ -194,15 +201,16 @@ class DenseMapBase : public DebugEpochBase {
194
201
// useful, because `lookup` cannot be used with non-default-constructible
195
202
// values.
196
203
template <typename U = std::remove_cv_t <ValueT>>
197
- ValueT lookup_or (const_arg_type_t <KeyT> Val, U &&Default) const {
204
+ [[nodiscard]] ValueT lookup_or (const_arg_type_t <KeyT> Val,
205
+ U &&Default) const {
198
206
if (const BucketT *Bucket = doFind (Val))
199
207
return Bucket->getSecond ();
200
208
return Default;
201
209
}
202
210
203
211
// / at - Return the entry for the specified key, or abort if no such
204
212
// / entry exists.
205
- const ValueT &at (const_arg_type_t <KeyT> Val) const {
213
+ [[nodiscard]] const ValueT &at (const_arg_type_t <KeyT> Val) const {
206
214
auto Iter = this ->find (std::move (Val));
207
215
assert (Iter != this ->end () && " DenseMap::at failed due to a missing key" );
208
216
return Iter->second ;
@@ -330,14 +338,16 @@ class DenseMapBase : public DebugEpochBase {
330
338
// / isPointerIntoBucketsArray - Return true if the specified pointer points
331
339
// / somewhere into the DenseMap's array of buckets (i.e. either to a key or
332
340
// / value in the DenseMap).
333
- bool isPointerIntoBucketsArray (const void *Ptr) const {
341
+ [[nodiscard]] bool isPointerIntoBucketsArray (const void *Ptr) const {
334
342
return Ptr >= getBuckets () && Ptr < getBucketsEnd ();
335
343
}
336
344
337
345
// / getPointerIntoBucketsArray() - Return an opaque pointer into the buckets
338
346
// / array. In conjunction with the previous method, this can be used to
339
347
// / determine whether an insertion caused the DenseMap to reallocate.
340
- const void *getPointerIntoBucketsArray () const { return getBuckets (); }
348
+ [[nodiscard]] const void *getPointerIntoBucketsArray () const {
349
+ return getBuckets ();
350
+ }
341
351
342
352
protected:
343
353
DenseMapBase () = default ;
@@ -649,7 +659,9 @@ class DenseMapBase : public DebugEpochBase {
649
659
// / This is just the raw memory used by DenseMap.
650
660
// / If entries are pointers to objects, the size of the referenced objects
651
661
// / are not included.
652
- size_t getMemorySize () const { return getNumBuckets () * sizeof (BucketT); }
662
+ [[nodiscard]] size_t getMemorySize () const {
663
+ return getNumBuckets () * sizeof (BucketT);
664
+ }
653
665
};
654
666
655
667
// / Equality comparison for DenseMap.
@@ -660,9 +672,9 @@ class DenseMapBase : public DebugEpochBase {
660
672
// / complexity is linear, worst case is O(N^2) (if every hash collides).
661
673
template <typename DerivedT, typename KeyT, typename ValueT, typename KeyInfoT,
662
674
typename BucketT>
663
- bool operator ==(
664
- const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &LHS,
665
- const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &RHS) {
675
+ [[nodiscard]] bool
676
+ operator ==( const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &LHS,
677
+ const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &RHS) {
666
678
if (LHS.size () != RHS.size ())
667
679
return false ;
668
680
@@ -680,9 +692,9 @@ bool operator==(
680
692
// / Equivalent to !(LHS == RHS). See operator== for performance notes.
681
693
template <typename DerivedT, typename KeyT, typename ValueT, typename KeyInfoT,
682
694
typename BucketT>
683
- bool operator !=(
684
- const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &LHS,
685
- const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &RHS) {
695
+ [[nodiscard]] bool
696
+ operator !=( const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &LHS,
697
+ const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &RHS) {
686
698
return !(LHS == RHS);
687
699
}
688
700
@@ -1220,15 +1232,15 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
1220
1232
const DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc> &I)
1221
1233
: DebugEpochBase::HandleBase(I), Ptr(I.Ptr), End(I.End) {}
1222
1234
1223
- reference operator *() const {
1235
+ [[nodiscard]] reference operator *() const {
1224
1236
assert (isHandleInSync () && " invalid iterator access!" );
1225
1237
assert (Ptr != End && " dereferencing end() iterator" );
1226
1238
return *Ptr;
1227
1239
}
1228
- pointer operator ->() const { return &operator *(); }
1240
+ [[nodiscard]] pointer operator ->() const { return &operator *(); }
1229
1241
1230
- friend bool operator ==(const DenseMapIterator &LHS,
1231
- const DenseMapIterator &RHS) {
1242
+ [[nodiscard]] friend bool operator ==(const DenseMapIterator &LHS,
1243
+ const DenseMapIterator &RHS) {
1232
1244
assert ((!LHS.getEpochAddress () || LHS.isHandleInSync ()) &&
1233
1245
" handle not in sync!" );
1234
1246
assert ((!RHS.getEpochAddress () || RHS.isHandleInSync ()) &&
@@ -1238,8 +1250,8 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
1238
1250
return LHS.Ptr == RHS.Ptr ;
1239
1251
}
1240
1252
1241
- friend bool operator !=(const DenseMapIterator &LHS,
1242
- const DenseMapIterator &RHS) {
1253
+ [[nodiscard]] friend bool operator !=(const DenseMapIterator &LHS,
1254
+ const DenseMapIterator &RHS) {
1243
1255
return !(LHS == RHS);
1244
1256
}
1245
1257
@@ -1277,7 +1289,8 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
1277
1289
};
1278
1290
1279
1291
template <typename KeyT, typename ValueT, typename KeyInfoT>
1280
- inline size_t capacity_in_bytes (const DenseMap<KeyT, ValueT, KeyInfoT> &X) {
1292
+ [[nodiscard]] inline size_t
1293
+ capacity_in_bytes (const DenseMap<KeyT, ValueT, KeyInfoT> &X) {
1281
1294
return X.getMemorySize ();
1282
1295
}
1283
1296
0 commit comments