Skip to content

Commit 0de265c

Browse files
[ADT] Consolidate assertSafeToReferenceAfterClear with "if constexpr" (NFC) (#161042)
This patch consolidates two implementations of assertSafeToReferenceAfterClear into a single template function.
1 parent f7dd258 commit 0de265c

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

llvm/include/llvm/ADT/SmallVector.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,18 @@ class SmallVectorTemplateCommon
199199
}
200200

201201
/// Check whether any part of the range will be invalidated by clearing.
202-
void assertSafeToReferenceAfterClear(const T *From, const T *To) {
203-
if (From == To)
204-
return;
205-
this->assertSafeToReferenceAfterResize(From, 0);
206-
this->assertSafeToReferenceAfterResize(To - 1, 0);
207-
}
208-
template <
209-
class ItTy,
210-
std::enable_if_t<!std::is_same<std::remove_const_t<ItTy>, T *>::value,
211-
bool> = false>
212-
void assertSafeToReferenceAfterClear(ItTy, ItTy) {}
202+
template <class ItTy>
203+
void assertSafeToReferenceAfterClear(ItTy From, ItTy To) {
204+
if constexpr (std::is_pointer_v<ItTy> &&
205+
std::is_same_v<
206+
std::remove_const_t<std::remove_pointer_t<ItTy>>,
207+
std::remove_const_t<T>>) {
208+
if (From == To)
209+
return;
210+
this->assertSafeToReferenceAfterResize(From, 0);
211+
this->assertSafeToReferenceAfterResize(To - 1, 0);
212+
}
213+
}
213214

214215
/// Check whether any part of the range will be invalidated by growing.
215216
template <class ItTy> void assertSafeToAddRange(ItTy From, ItTy To) {

0 commit comments

Comments
 (0)