[llvm] c3edab8 - ADT: Avoid repeating iterator adaptor/facade template params, NFC

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 12 14:04:54 PST 2021


Author: Duncan P. N. Exon Smith
Date: 2021-11-12T14:00:08-08:00
New Revision: c3edab8f781d0c3cf063ec0c675ad7bd7c3b65b8

URL: https://github.com/llvm/llvm-project/commit/c3edab8f781d0c3cf063ec0c675ad7bd7c3b65b8
DIFF: https://github.com/llvm/llvm-project/commit/c3edab8f781d0c3cf063ec0c675ad7bd7c3b65b8.diff

LOG: 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.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/STLExtras.h
    llvm/include/llvm/DebugInfo/PDB/Native/DbiModuleList.h
    llvm/include/llvm/DebugInfo/PDB/Native/HashTable.h
    llvm/unittests/ADT/IteratorTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index d3a9ce8e76a05..48f15b02283a6 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<ItTy>::
diff erence_type,
           std::remove_reference_t<ReferenceTy> *, ReferenceTy> {
 public:
-  using BaseT = mapped_iterator_base<DerivedT, ItTy, ReferenceTy>;
+  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, PredicateT, IterTag>,
-      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 <typename WrappedIteratorT, typename PredicateT,
           typename IterTag = std::forward_iterator_tag>
 class filter_iterator_impl
     : public filter_iterator_base<WrappedIteratorT, PredicateT, IterTag> {
-  using BaseT = filter_iterator_base<WrappedIteratorT, PredicateT, IterTag>;
-
 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<WrappedIteratorT, PredicateT,
                            std::bidirectional_iterator_tag>
     : public filter_iterator_base<WrappedIteratorT, PredicateT,
                                   std::bidirectional_iterator_tag> {
-  using BaseT = filter_iterator_base<WrappedIteratorT, PredicateT,
-                                     std::bidirectional_iterator_tag>;
+  using BaseT = typename filter_iterator_impl::filter_iterator_base;
+
   void findPrevValid() {
     while (!this->Pred(*this->I))
       BaseT::operator--();
@@ -544,9 +537,7 @@ template <typename WrappedIteratorT>
 class early_inc_iterator_impl
     : public iterator_adaptor_base<early_inc_iterator_impl<WrappedIteratorT>,
                                    WrappedIteratorT, std::input_iterator_tag> {
-  using BaseT =
-      iterator_adaptor_base<early_inc_iterator_impl<WrappedIteratorT>,
-                            WrappedIteratorT, std::input_iterator_tag>;
+  using BaseT = typename early_inc_iterator_impl::iterator_adaptor_base;
 
   using PointerT = typename std::iterator_traits<WrappedIteratorT>::pointer;
 
@@ -1112,8 +1103,7 @@ template <typename DerivedT, typename BaseT, typename T,
           typename PointerT = T *, typename ReferenceT = T &>
 class indexed_accessor_range_base {
 public:
-  using RangeBaseT =
-      indexed_accessor_range_base<DerivedT, BaseT, T, PointerT, ReferenceT>;
+  using RangeBaseT = indexed_accessor_range_base;
 
   /// An iterator element of this range.
   class iterator : public indexed_accessor_iterator<iterator, BaseT, T,
@@ -1126,8 +1116,7 @@ class indexed_accessor_range_base {
 
   private:
     iterator(BaseT owner, ptr
diff _t curIndex)
-        : indexed_accessor_iterator<iterator, BaseT, T, PointerT, ReferenceT>(
-              owner, curIndex) {}
+        : iterator::indexed_accessor_iterator(owner, curIndex) {}
 
     /// Allow access to the constructor.
     friend indexed_accessor_range_base<DerivedT, BaseT, T, PointerT,

diff  --git a/llvm/include/llvm/DebugInfo/PDB/Native/DbiModuleList.h b/llvm/include/llvm/DebugInfo/PDB/Native/DbiModuleList.h
index 5fb13ad30e91b..de5b46f216721 100644
--- a/llvm/include/llvm/DebugInfo/PDB/Native/DbiModuleList.h
+++ b/llvm/include/llvm/DebugInfo/PDB/Native/DbiModuleList.h
@@ -31,9 +31,7 @@ struct FileInfoSubstreamHeader;
 class DbiModuleSourceFilesIterator
     : public iterator_facade_base<DbiModuleSourceFilesIterator,
                                   std::random_access_iterator_tag, StringRef> {
-  using BaseType =
-      iterator_facade_base<DbiModuleSourceFilesIterator,
-                           std::random_access_iterator_tag, StringRef>;
+  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 95c0a89551ed5..474bd796b2b3d 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<HashTableIterator<ValueT>,
                                   std::forward_iterator_tag,
                                   const std::pair<uint32_t, ValueT>> {
+  using BaseT = typename HashTableIterator::iterator_facade_base;
   friend HashTable<ValueT>;
 
   HashTableIterator(const HashTable<ValueT> &Map, uint32_t Index,
@@ -76,9 +77,7 @@ class HashTableIterator
 
   // Implement postfix op++ in terms of prefix op++ by using the superclass
   // implementation.
-  using iterator_facade_base<HashTableIterator<ValueT>,
-                             std::forward_iterator_tag,
-                             const std::pair<uint32_t, ValueT>>::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 b443afc0fc696..4e69ad28aabe0 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 <class T>
 struct PointerWrapper : public iterator_adaptor_base<PointerWrapper<T>, T *> {
-  PointerWrapper(T *I) : iterator_adaptor_base<PointerWrapper, T *>(I) {}
+  PointerWrapper(T *I) : PointerWrapper::iterator_adaptor_base(I) {}
 };
 struct IntProxy {
   int &I;
@@ -71,10 +71,7 @@ struct PointerProxyWrapper
     : public iterator_adaptor_base<PointerProxyWrapper<T, ProxyT>, T *,
                                    std::random_access_iterator_tag, T,
                                    ptr
diff _t, T *, ProxyT> {
-  PointerProxyWrapper(T *I)
-      : iterator_adaptor_base<PointerProxyWrapper, T *,
-                              std::random_access_iterator_tag, T, ptr
diff _t,
-                              T *, ProxyT>(I) {}
+  PointerProxyWrapper(T *I) : PointerProxyWrapper::iterator_adaptor_base(I) {}
 };
 using IntIterator = PointerWrapper<int>;
 using ConstIntIterator = PointerWrapper<const int>;
@@ -318,10 +315,7 @@ TEST(FilterIteratorTest, Composition) {
 TEST(FilterIteratorTest, InputIterator) {
   struct InputIterator
       : iterator_adaptor_base<InputIterator, int *, std::input_iterator_tag> {
-    using BaseT =
-        iterator_adaptor_base<InputIterator, int *, std::input_iterator_tag>;
-
-    InputIterator(int *It) : BaseT(It) {}
+    InputIterator(int *It) : InputIterator::iterator_adaptor_base(It) {}
   };
 
   auto IsOdd = [](int N) { return N % 2 == 1; };


        


More information about the llvm-commits mailing list