[PATCH] D130779: [NFC] Remove some boilerplate from SmallVector header
Dawid Jurczak via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 2 02:47:52 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG78650b786188: [NFC] Remove some boilerplate from SmallVector header (authored by yurai007).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130779/new/
https://reviews.llvm.org/D130779
Files:
llvm/include/llvm/ADT/SmallVector.h
Index: llvm/include/llvm/ADT/SmallVector.h
===================================================================
--- llvm/include/llvm/ADT/SmallVector.h
+++ llvm/include/llvm/ADT/SmallVector.h
@@ -34,6 +34,11 @@
template <typename IteratorT> class iterator_range;
+template <class Iterator>
+using EnableIfConvertibleToInputIterator = std::enable_if_t<std::is_convertible<
+ typename std::iterator_traits<Iterator>::iterator_category,
+ std::input_iterator_tag>::value>;
+
/// This is all the stuff common to all SmallVectors.
///
/// The template parameter specifies the type which should be used to hold the
@@ -660,11 +665,8 @@
void swap(SmallVectorImpl &RHS);
/// Add the specified range to the end of the SmallVector.
- template <typename in_iter,
- typename = std::enable_if_t<std::is_convertible<
- typename std::iterator_traits<in_iter>::iterator_category,
- std::input_iterator_tag>::value>>
- void append(in_iter in_start, in_iter in_end) {
+ template <typename ItTy, typename = EnableIfConvertibleToInputIterator<ItTy>>
+ void append(ItTy in_start, ItTy in_end) {
this->assertSafeToAddRange(in_start, in_end);
size_type NumInputs = std::distance(in_start, in_end);
this->reserve(this->size() + NumInputs);
@@ -704,11 +706,8 @@
// FIXME: Consider assigning over existing elements, rather than clearing &
// re-initializing them - for all assign(...) variants.
- template <typename in_iter,
- typename = std::enable_if_t<std::is_convertible<
- typename std::iterator_traits<in_iter>::iterator_category,
- std::input_iterator_tag>::value>>
- void assign(in_iter in_start, in_iter in_end) {
+ template <typename ItTy, typename = EnableIfConvertibleToInputIterator<ItTy>>
+ void assign(ItTy in_start, ItTy in_end) {
this->assertSafeToReferenceAfterClear(in_start, in_end);
clear();
append(in_start, in_end);
@@ -858,10 +857,7 @@
return I;
}
- template <typename ItTy,
- typename = std::enable_if_t<std::is_convertible<
- typename std::iterator_traits<ItTy>::iterator_category,
- std::input_iterator_tag>::value>>
+ template <typename ItTy, typename = EnableIfConvertibleToInputIterator<ItTy>>
iterator insert(iterator I, ItTy From, ItTy To) {
// Convert iterator to elt# to avoid invalidating iterator when we reserve()
size_t InsertElt = I - this->begin();
@@ -1197,10 +1193,7 @@
this->assign(Size, Value);
}
- template <typename ItTy,
- typename = std::enable_if_t<std::is_convertible<
- typename std::iterator_traits<ItTy>::iterator_category,
- std::input_iterator_tag>::value>>
+ template <typename ItTy, typename = EnableIfConvertibleToInputIterator<ItTy>>
SmallVector(ItTy S, ItTy E) : SmallVectorImpl<T>(N) {
this->append(S, E);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130779.449235.patch
Type: text/x-patch
Size: 2922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220802/0e1c6c7f/attachment.bin>
More information about the llvm-commits
mailing list