Unverified Commit 2fab15d8 authored by Giulio Eulisse's avatar Giulio Eulisse Committed by GitHub
Browse files

Inline operator== and operator!= (#67958)



Avoid triggering -Wnon-template-friend on newer GCC.

---------

Co-authored-by: default avatarRichard Smith <richard@metafoo.co.uk>
parent 96dd50ee
Loading
Loading
Loading
Loading
+23 −25
Original line number Diff line number Diff line
@@ -209,35 +209,33 @@ public:
      return PagePtr[ElementIdx % PageSize];
    }

    friend bool operator==(MaterializedIterator const &LHS,
                           MaterializedIterator const &RHS);
    friend bool operator!=(MaterializedIterator const &LHS,
                           MaterializedIterator const &RHS);
    /// Equality operator.
    friend bool operator==(const MaterializedIterator &LHS,
                           const MaterializedIterator &RHS) {
      return LHS.equals(RHS);
    }

    [[nodiscard]] size_t getIndex() const { return ElementIdx; }
  };

  /// Equality operator.
  friend bool operator==(MaterializedIterator const &LHS,
                         MaterializedIterator const &RHS) {
    assert(LHS.PV == RHS.PV);
    // Make sure we are comparing either end iterators or iterators pointing
    // to materialized elements.
    // It should not be possible to build two iterators pointing to non
    // materialized elements.
    assert(LHS.ElementIdx == LHS.PV->Size ||
           (LHS.ElementIdx < LHS.PV->Size &&
            LHS.PV->PageToDataPtrs[LHS.ElementIdx / PageSize]));
    assert(RHS.ElementIdx == RHS.PV->Size ||
           (RHS.ElementIdx < RHS.PV->Size &&
            RHS.PV->PageToDataPtrs[RHS.ElementIdx / PageSize]));
    return LHS.ElementIdx == RHS.ElementIdx;
    friend bool operator!=(const MaterializedIterator &LHS,
                           const MaterializedIterator &RHS) {
      return !(LHS == RHS);
    }

  friend bool operator!=(MaterializedIterator const &LHS,
                         MaterializedIterator const &RHS) {
    return !(LHS == RHS);
  private:
    void verify() const {
      assert(
          ElementIdx == PV->Size ||
          (ElementIdx < PV->Size && PV->PageToDataPtrs[ElementIdx / PageSize]));
    }

    bool equals(const MaterializedIterator &Other) const {
      assert(PV == Other.PV);
      verify();
      Other.verify();
      return ElementIdx == Other.ElementIdx;
    }
  };

  /// Iterators over the materialized elements of the vector.
  ///