forked from OSchip/llvm-project
[NFC] Remove some boilerplate from SmallVector header
In SmallVector header we use couple of times exactly same enable_if, in this change we de-duplicate it and declare only once. Extracted from: https://reviews.llvm.org/D129990 Differential Revision: https://reviews.llvm.org/D130779
This commit is contained in:
parent
09ca1c0656
commit
78650b7861
|
@ -34,6 +34,11 @@ namespace llvm {
|
|||
|
||||
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 @@ public:
|
|||
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 @@ public:
|
|||
// 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 @@ public:
|
|||
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 @@ public:
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue