@@ -75,37 +75,39 @@ class DenseMapBase : public DebugEpochBase {
7575 using const_iterator =
7676 DenseMapIterator<KeyT, ValueT, KeyInfoT, BucketT, true >;
7777
78- inline iterator begin () {
78+ [[nodiscard]] inline iterator begin () {
7979 return iterator::makeBegin (buckets (), empty (), *this );
8080 }
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 {
8385 return const_iterator::makeBegin (buckets (), empty (), *this );
8486 }
85- inline const_iterator end () const {
87+ [[nodiscard]] inline const_iterator end () const {
8688 return const_iterator::makeEnd (buckets (), *this );
8789 }
8890
8991 // Return an iterator to iterate over keys in the map.
90- inline auto keys () {
92+ [[nodiscard]] inline auto keys () {
9193 return map_range (*this , [](const BucketT &P) { return P.getFirst (); });
9294 }
9395
9496 // Return an iterator to iterate over values in the map.
95- inline auto values () {
97+ [[nodiscard]] inline auto values () {
9698 return map_range (*this , [](const BucketT &P) { return P.getSecond (); });
9799 }
98100
99- inline auto keys () const {
101+ [[nodiscard]] inline auto keys () const {
100102 return map_range (*this , [](const BucketT &P) { return P.getFirst (); });
101103 }
102104
103- inline auto values () const {
105+ [[nodiscard]] inline auto values () const {
104106 return map_range (*this , [](const BucketT &P) { return P.getSecond (); });
105107 }
106108
107109 [[nodiscard]] bool empty () const { return getNumEntries () == 0 ; }
108- unsigned size () const { return getNumEntries (); }
110+ [[nodiscard]] unsigned size () const { return getNumEntries (); }
109111
110112 // / Grow the densemap so that it can contain at least \p NumEntries items
111113 // / before resizing again.
@@ -153,38 +155,43 @@ class DenseMapBase : public DebugEpochBase {
153155 }
154156
155157 // / 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 {
157159 return doFind (Val) != nullptr ;
158160 }
159161
160162 // / 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 {
162164 return contains (Val) ? 1 : 0 ;
163165 }
164166
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+ }
167173
168174 // / Alternate version of find() which allows a different, and possibly
169175 // / less expensive, key type.
170176 // / The DenseMapInfo is responsible for supplying methods
171177 // / getHashValue(LookupKeyT) and isEqual(LookupKeyT, KeyT) for each key
172178 // / type used.
173- template <class LookupKeyT > iterator find_as (const LookupKeyT &Val) {
179+ template <class LookupKeyT >
180+ [[nodiscard]] iterator find_as (const LookupKeyT &Val) {
174181 if (BucketT *Bucket = doFind (Val))
175182 return makeIterator (Bucket);
176183 return end ();
177184 }
178185 template <class LookupKeyT >
179- const_iterator find_as (const LookupKeyT &Val) const {
186+ [[nodiscard]] const_iterator find_as (const LookupKeyT &Val) const {
180187 if (const BucketT *Bucket = doFind (Val))
181188 return makeConstIterator (Bucket);
182189 return end ();
183190 }
184191
185192 // / lookup - Return the entry for the specified key, or a default
186193 // / 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 {
188195 if (const BucketT *Bucket = doFind (Val))
189196 return Bucket->getSecond ();
190197 return ValueT ();
@@ -194,15 +201,16 @@ class DenseMapBase : public DebugEpochBase {
194201 // useful, because `lookup` cannot be used with non-default-constructible
195202 // values.
196203 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 {
198206 if (const BucketT *Bucket = doFind (Val))
199207 return Bucket->getSecond ();
200208 return Default;
201209 }
202210
203211 // / at - Return the entry for the specified key, or abort if no such
204212 // / 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 {
206214 auto Iter = this ->find (std::move (Val));
207215 assert (Iter != this ->end () && " DenseMap::at failed due to a missing key" );
208216 return Iter->second ;
@@ -330,14 +338,16 @@ class DenseMapBase : public DebugEpochBase {
330338 // / isPointerIntoBucketsArray - Return true if the specified pointer points
331339 // / somewhere into the DenseMap's array of buckets (i.e. either to a key or
332340 // / value in the DenseMap).
333- bool isPointerIntoBucketsArray (const void *Ptr) const {
341+ [[nodiscard]] bool isPointerIntoBucketsArray (const void *Ptr) const {
334342 return Ptr >= getBuckets () && Ptr < getBucketsEnd ();
335343 }
336344
337345 // / getPointerIntoBucketsArray() - Return an opaque pointer into the buckets
338346 // / array. In conjunction with the previous method, this can be used to
339347 // / 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+ }
341351
342352protected:
343353 DenseMapBase () = default ;
@@ -656,7 +666,9 @@ class DenseMapBase : public DebugEpochBase {
656666 // / This is just the raw memory used by DenseMap.
657667 // / If entries are pointers to objects, the size of the referenced objects
658668 // / are not included.
659- size_t getMemorySize () const { return getNumBuckets () * sizeof (BucketT); }
669+ [[nodiscard]] size_t getMemorySize () const {
670+ return getNumBuckets () * sizeof (BucketT);
671+ }
660672};
661673
662674// / Equality comparison for DenseMap.
@@ -667,9 +679,9 @@ class DenseMapBase : public DebugEpochBase {
667679// / complexity is linear, worst case is O(N^2) (if every hash collides).
668680template <typename DerivedT, typename KeyT, typename ValueT, typename KeyInfoT,
669681 typename BucketT>
670- bool operator ==(
671- const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &LHS,
672- const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &RHS) {
682+ [[nodiscard]] bool
683+ operator ==( const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &LHS,
684+ const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &RHS) {
673685 if (LHS.size () != RHS.size ())
674686 return false ;
675687
@@ -687,9 +699,9 @@ bool operator==(
687699// / Equivalent to !(LHS == RHS). See operator== for performance notes.
688700template <typename DerivedT, typename KeyT, typename ValueT, typename KeyInfoT,
689701 typename BucketT>
690- bool operator !=(
691- const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &LHS,
692- const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &RHS) {
702+ [[nodiscard]] bool
703+ operator !=( const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &LHS,
704+ const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &RHS) {
693705 return !(LHS == RHS);
694706}
695707
@@ -1227,15 +1239,15 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
12271239 const DenseMapIterator<KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc> &I)
12281240 : DebugEpochBase::HandleBase(I), Ptr(I.Ptr), End(I.End) {}
12291241
1230- reference operator *() const {
1242+ [[nodiscard]] reference operator *() const {
12311243 assert (isHandleInSync () && " invalid iterator access!" );
12321244 assert (Ptr != End && " dereferencing end() iterator" );
12331245 return *Ptr;
12341246 }
1235- pointer operator ->() const { return &operator *(); }
1247+ [[nodiscard]] pointer operator ->() const { return &operator *(); }
12361248
1237- friend bool operator ==(const DenseMapIterator &LHS,
1238- const DenseMapIterator &RHS) {
1249+ [[nodiscard]] friend bool operator ==(const DenseMapIterator &LHS,
1250+ const DenseMapIterator &RHS) {
12391251 assert ((!LHS.getEpochAddress () || LHS.isHandleInSync ()) &&
12401252 " handle not in sync!" );
12411253 assert ((!RHS.getEpochAddress () || RHS.isHandleInSync ()) &&
@@ -1245,8 +1257,8 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
12451257 return LHS.Ptr == RHS.Ptr ;
12461258 }
12471259
1248- friend bool operator !=(const DenseMapIterator &LHS,
1249- const DenseMapIterator &RHS) {
1260+ [[nodiscard]] friend bool operator !=(const DenseMapIterator &LHS,
1261+ const DenseMapIterator &RHS) {
12501262 return !(LHS == RHS);
12511263 }
12521264
@@ -1284,7 +1296,8 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
12841296};
12851297
12861298template <typename KeyT, typename ValueT, typename KeyInfoT>
1287- inline size_t capacity_in_bytes (const DenseMap<KeyT, ValueT, KeyInfoT> &X) {
1299+ [[nodiscard]] inline size_t
1300+ capacity_in_bytes (const DenseMap<KeyT, ValueT, KeyInfoT> &X) {
12881301 return X.getMemorySize ();
12891302}
12901303
0 commit comments