From c3edab8f781d0c3cf063ec0c675ad7bd7c3b65b8 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Fri, 12 Nov 2021 13:50:29 -0800 Subject: [PATCH] ADT: Avoid repeating iterator adaptor/facade template params, NFC Take advantage of class name injection to avoid redundantly specifying template parameters of iterator adaptor/facade base classes. No functionality change, although the private typedefs changed in a couple of cases. - Added a private typedef HashTableIterator::BaseT, following the pattern from r207084 / 3478d4b164e8d3eba01f5bfa3fc5bfb287a78b97, to pre-emptively appease MSVC (maybe it's not necessary anymore but looks like we do this pretty consistently). Otherwise, I removed private - Removed private typedefs filter_iterator_impl::BaseT and FilterIteratorTest::InputIterator::BaseT since there was only one use of each and the definition was no longer interesting. --- llvm/include/llvm/ADT/STLExtras.h | 27 +++++++--------------- .../llvm/DebugInfo/PDB/Native/DbiModuleList.h | 4 +--- llvm/include/llvm/DebugInfo/PDB/Native/HashTable.h | 5 ++-- llvm/unittests/ADT/IteratorTest.cpp | 12 +++------- 4 files changed, 14 insertions(+), 34 deletions(-) diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index d3a9ce8..48f15b0 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -321,7 +321,7 @@ class mapped_iterator_base typename std::iterator_traits::difference_type, std::remove_reference_t *, ReferenceTy> { public: - using BaseT = mapped_iterator_base; + using BaseT = mapped_iterator_base; mapped_iterator_base(ItTy U) : mapped_iterator_base::iterator_adaptor_base(std::move(U)) {} @@ -401,12 +401,7 @@ class filter_iterator_base typename std::common_type< IterTag, typename std::iterator_traits< WrappedIteratorT>::iterator_category>::type> { - using BaseT = iterator_adaptor_base< - filter_iterator_base, - WrappedIteratorT, - typename std::common_type< - IterTag, typename std::iterator_traits< - WrappedIteratorT>::iterator_category>::type>; + using BaseT = typename filter_iterator_base::iterator_adaptor_base; protected: WrappedIteratorT End; @@ -441,12 +436,10 @@ template class filter_iterator_impl : public filter_iterator_base { - using BaseT = filter_iterator_base; - public: filter_iterator_impl(WrappedIteratorT Begin, WrappedIteratorT End, PredicateT Pred) - : BaseT(Begin, End, Pred) {} + : filter_iterator_impl::filter_iterator_base(Begin, End, Pred) {} }; /// Specialization of filter_iterator_base for bidirectional iteration. @@ -455,8 +448,8 @@ class filter_iterator_impl : public filter_iterator_base { - using BaseT = filter_iterator_base; + using BaseT = typename filter_iterator_impl::filter_iterator_base; + void findPrevValid() { while (!this->Pred(*this->I)) BaseT::operator--(); @@ -544,9 +537,7 @@ template class early_inc_iterator_impl : public iterator_adaptor_base, WrappedIteratorT, std::input_iterator_tag> { - using BaseT = - iterator_adaptor_base, - WrappedIteratorT, std::input_iterator_tag>; + using BaseT = typename early_inc_iterator_impl::iterator_adaptor_base; using PointerT = typename std::iterator_traits::pointer; @@ -1112,8 +1103,7 @@ template class indexed_accessor_range_base { public: - using RangeBaseT = - indexed_accessor_range_base; + using RangeBaseT = indexed_accessor_range_base; /// An iterator element of this range. class iterator : public indexed_accessor_iterator( - owner, curIndex) {} + : iterator::indexed_accessor_iterator(owner, curIndex) {} /// Allow access to the constructor. friend indexed_accessor_range_base { - using BaseType = - iterator_facade_base; + using BaseType = typename DbiModuleSourceFilesIterator::iterator_facade_base; public: DbiModuleSourceFilesIterator(const DbiModuleList &Modules, uint32_t Modi, diff --git a/llvm/include/llvm/DebugInfo/PDB/Native/HashTable.h b/llvm/include/llvm/DebugInfo/PDB/Native/HashTable.h index 95c0a89..474bd79 100644 --- a/llvm/include/llvm/DebugInfo/PDB/Native/HashTable.h +++ b/llvm/include/llvm/DebugInfo/PDB/Native/HashTable.h @@ -38,6 +38,7 @@ class HashTableIterator : public iterator_facade_base, std::forward_iterator_tag, const std::pair> { + using BaseT = typename HashTableIterator::iterator_facade_base; friend HashTable; HashTableIterator(const HashTable &Map, uint32_t Index, @@ -76,9 +77,7 @@ public: // Implement postfix op++ in terms of prefix op++ by using the superclass // implementation. - using iterator_facade_base, - std::forward_iterator_tag, - const std::pair>::operator++; + using BaseT::operator++; HashTableIterator &operator++() { while (Index < Map->Buckets.size()) { ++Index; diff --git a/llvm/unittests/ADT/IteratorTest.cpp b/llvm/unittests/ADT/IteratorTest.cpp index b443afc..4e69ad2 100644 --- a/llvm/unittests/ADT/IteratorTest.cpp +++ b/llvm/unittests/ADT/IteratorTest.cpp @@ -55,7 +55,7 @@ using IsAdaptedIterCategorySame = // Check that dereferencing works correctly adapting pointers and proxies. template struct PointerWrapper : public iterator_adaptor_base, T *> { - PointerWrapper(T *I) : iterator_adaptor_base(I) {} + PointerWrapper(T *I) : PointerWrapper::iterator_adaptor_base(I) {} }; struct IntProxy { int &I; @@ -71,10 +71,7 @@ struct PointerProxyWrapper : public iterator_adaptor_base, T *, std::random_access_iterator_tag, T, ptrdiff_t, T *, ProxyT> { - PointerProxyWrapper(T *I) - : iterator_adaptor_base(I) {} + PointerProxyWrapper(T *I) : PointerProxyWrapper::iterator_adaptor_base(I) {} }; using IntIterator = PointerWrapper; using ConstIntIterator = PointerWrapper; @@ -318,10 +315,7 @@ TEST(FilterIteratorTest, Composition) { TEST(FilterIteratorTest, InputIterator) { struct InputIterator : iterator_adaptor_base { - using BaseT = - iterator_adaptor_base; - - InputIterator(int *It) : BaseT(It) {} + InputIterator(int *It) : InputIterator::iterator_adaptor_base(It) {} }; auto IsOdd = [](int N) { return N % 2 == 1; }; -- 2.7.4