@@ -13,10 +13,11 @@ namespace {
1313using power_grid_model::Idx;
1414using power_grid_model::IdxRange;
1515using power_grid_model::IdxVector;
16+ using power_grid_model::IntS;
1617using power_grid_model::IteratorFacade;
1718using power_grid_model::detail::iterator_facadeable_c;
1819
19- enum class IteratorFacadeableCalls : Idx {
20+ enum class IteratorFacadeableCalls : IntS {
2021 none = 0 ,
2122 dereference = 1 ,
2223 advance = 2 ,
@@ -49,48 +50,50 @@ template <advance_type_c advance_type_t, typename UnderlyingType> class BaseTest
4950 ? IteratorFacadeableCalls::decrement
5051 : IteratorFacadeableCalls::advance;
5152
52- mutable std::optional<IteratorFacadeableCalls> last_call;
53-
5453 constexpr BaseTestIterator (std::remove_cvref_t <underlying> it) : IteratorFacade{*this }, it_{std::move (it)} {}
5554
5655 constexpr auto operator *() -> reference {
57- last_call = IteratorFacadeableCalls::dereference;
56+ last_call_ = IteratorFacadeableCalls::dereference;
5857 return *it_;
5958 }
6059 constexpr auto operator *() const -> std::add_lvalue_reference_t <std::add_const_t <value_type>> {
61- last_call = IteratorFacadeableCalls::dereference;
60+ last_call_ = IteratorFacadeableCalls::dereference;
6261 return *it_;
6362 }
6463
6564 friend constexpr auto operator <=>(BaseTestIterator const & first,
6665 BaseTestIterator const & second) -> std::strong_ordering {
67- first.last_call = IteratorFacadeableCalls::distance_to;
66+ first.last_call_ = IteratorFacadeableCalls::distance_to;
6867 return *first.it_ <=> *second.it_ ;
6968 }
7069
7170 constexpr decltype (auto ) operator+=(difference_type n) {
72- last_call = IteratorFacadeableCalls::advance;
71+ last_call_ = IteratorFacadeableCalls::advance;
7372 it_ += n;
7473 return *this ;
7574 }
7675 friend constexpr auto operator -(BaseTestIterator const & first, BaseTestIterator const & second) -> difference_type {
77- first.last_call = IteratorFacadeableCalls::distance_to;
76+ first.last_call_ = IteratorFacadeableCalls::distance_to;
7877 return first.it_ - second.it_ ;
7978 }
8079
80+ constexpr std::optional<IteratorFacadeableCalls> const & last_call () const { return last_call_; }
81+ constexpr void reset () { last_call_ = std::nullopt ; }
82+
8183 private:
8284 underlying it_;
85+ mutable std::optional<IteratorFacadeableCalls> last_call_; // mutable to allow const methods to set it
8386
8487 constexpr void increment ()
8588 requires std::same_as<advance_type_t, with_increment_decrement_t>
8689 {
87- last_call = IteratorFacadeableCalls::increment;
90+ last_call_ = IteratorFacadeableCalls::increment;
8891 ++it_;
8992 }
9093 constexpr void decrement ()
9194 requires std::same_as<advance_type_t, with_increment_decrement_t>
9295 {
93- last_call = IteratorFacadeableCalls::decrement;
96+ last_call_ = IteratorFacadeableCalls::decrement;
9497 --it_;
9598 }
9699};
@@ -170,26 +173,29 @@ TEST_CASE_TEMPLATE("Test IteratorFacade", T, TestIdxVectorIterator, TestIdxVecto
170173 }
171174 SUBCASE (" Incremented/Decremented calls" ) {
172175 auto it = TestIterator{vec.begin () + 5 };
173- REQUIRE (!it.last_call .has_value ());
176+ REQUIRE (!it.last_call () .has_value ());
174177
175178 ++it;
176- REQUIRE (it.last_call .has_value ());
177- CHECK (it.last_call .value () == TestIterator::increment_style);
178- it.last_call .reset ();
179+ REQUIRE (it.last_call ().has_value ());
180+ CHECK (it.last_call ().value () == TestIterator::increment_style);
181+ it.reset ();
182+ REQUIRE (!it.last_call ().has_value ());
179183
180184 it++;
181- REQUIRE (it.last_call .has_value ());
182- CHECK (it.last_call .value () == TestIterator::increment_style);
183- it.last_call .reset ();
185+ REQUIRE (it.last_call ().has_value ());
186+ CHECK (it.last_call ().value () == TestIterator::increment_style);
187+ it.reset ();
188+ REQUIRE (!it.last_call ().has_value ());
184189
185190 --it;
186- REQUIRE (it.last_call .has_value ());
187- CHECK (it.last_call .value () == TestIterator::decrement_style);
188- it.last_call .reset ();
191+ REQUIRE (it.last_call ().has_value ());
192+ CHECK (it.last_call ().value () == TestIterator::decrement_style);
193+ it.reset ();
194+ REQUIRE (!it.last_call ().has_value ());
189195
190196 it--;
191- REQUIRE (it.last_call .has_value ());
192- CHECK (it.last_call .value () == TestIterator::decrement_style);
193- it.last_call . reset ();
197+ REQUIRE (it.last_call () .has_value ());
198+ CHECK (it.last_call () .value () == TestIterator::decrement_style);
199+ it.reset ();
194200 }
195201}
0 commit comments