From 1834109040683caf411cd50aa01d346b450ada67 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20M=C3=BCller?= <stefan.mueller@aksdb.de>
Date: Mon, 23 Jun 2025 20:51:16 +0200
Subject: [PATCH] Change GraphBase::NeighborIterator to use pointer to graph
 instead of reference

This enables default copy-assignment operator and copy constructor.
Also removed GraphBase::NeighborIterator::operator!=(), since it will be generated from the equality operator.
---
 include/aoc/common/GraphBase.hpp | 16 ++++++----------
 src/common/GraphBase.cpp         |  4 ++--
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/include/aoc/common/GraphBase.hpp b/include/aoc/common/GraphBase.hpp
index 3686bd5..93a59e6 100644
--- a/include/aoc/common/GraphBase.hpp
+++ b/include/aoc/common/GraphBase.hpp
@@ -46,19 +46,19 @@ class GraphBase
         using reference = const value_type&;
         using iterator_category = std::forward_iterator_tag;
 
-        NeighborIterator(const GraphBase& graph, const int vertex)
+        NeighborIterator(const GraphBase* graph, const int vertex)
             : graph_{ graph }, incidence_{ -1 }, value_{ -1, -1 }
         {
-            if (vertex >= 0 && vertex < graph_.firstVertexIncidences.size())
+            if (vertex >= 0 && vertex < graph_->getNVertices())
             {
-                setIncidence(graph_.firstVertexIncidences[vertex]);
+                setIncidence(graph_->firstVertexIncidences[vertex]);
             }
         };
         NeighborIterator& operator++()
         {
             if (incidence_ >= 0)
             {
-                setIncidence(graph_.nextIncidences[incidence_]);
+                setIncidence(graph_->nextIncidences[incidence_]);
             }
             return *this;
         }
@@ -72,10 +72,6 @@ class GraphBase
         {
             return incidence_ == other.incidence_;
         }
-        bool operator!=(NeighborIterator other) const
-        {
-            return !(*this == other);
-        }
         const reference operator*() const
         {
             return value_;
@@ -86,7 +82,7 @@ class GraphBase
         }
 
     private:
-        const GraphBase& graph_;
+        const GraphBase* graph_;
         int incidence_;
         value_type value_;
         void setIncidence(const int incidence)
@@ -94,7 +90,7 @@ class GraphBase
             incidence_ = incidence;
             if (incidence_ >= 0)
             {
-                value_ = { graph_.incidenceVertices[incidence_], incidence_ >> 1 };
+                value_ = { graph_->incidenceVertices[incidence_], incidence_ >> 1 };
             }
         }
     };
diff --git a/src/common/GraphBase.cpp b/src/common/GraphBase.cpp
index 702a9a0..56b6bef 100644
--- a/src/common/GraphBase.cpp
+++ b/src/common/GraphBase.cpp
@@ -41,12 +41,12 @@ bool GraphBase::areAdjacent(const int vertex1, const int vertex2) const
 
 GraphBase::NeighborIterator GraphBase::begin(const int vertex) const
 {
-    return { *this, vertex };
+    return { this, vertex };
 }
 
 GraphBase::NeighborIterator GraphBase::end() const
 {
-    return { *this, -1 };
+    return { this, -1 };
 }
 
 int GraphBase::addVertexInternal()