diff --git a/src/lib/iter-adapter.hpp b/src/lib/iter-adapter.hpp index 49f080846..34e069f77 100644 --- a/src/lib/iter-adapter.hpp +++ b/src/lib/iter-adapter.hpp @@ -706,23 +706,37 @@ namespace lib { class AddressExposingIter : public lib::BoolCheckable > { + public: + typedef typename IT::value_type ** pointer; + typedef typename IT::value_type *& reference; + typedef typename IT::value_type * value_type; + + private: IT i_; ///< nested source iterator + mutable value_type currPtr_; + + + void + takeAddress() + { + if (i_.isValid()) + currPtr_ = & (*i_); + else + currPtr_ = 0; + } + public: - typedef typename IT::value_type * value_type; - typedef typename IT::value_type ** pointer; - typedef typename IT::value_type *& reference; - - - /** AddressExposingIter is always created * by wrapping an existing iterator. */ explicit AddressExposingIter (IT srcIter) : i_(srcIter) - { } + { + takeAddress(); + } @@ -730,22 +744,28 @@ namespace lib { /* === lumiera forward iterator concept === */ - value_type + /** @return address of the source iteraor's current result + * @warning exposing a reference to an internal pointer for sake of compatibility. + * Clients must not store that reference, but rather use it to initialise + * a copy. The internal pointer exposed here will be changed on increment. + */ + reference operator*() const { - return &(*i_); + return currPtr_; } - typename IT::pointer + pointer operator->() const { - return i_.operator->(); + return currPtr_; } AddressExposingIter& operator++() { ++i_; + takeAddress(); return *this; } diff --git a/tests/library/hierarchy-orientation-indicator-test.cpp b/tests/library/hierarchy-orientation-indicator-test.cpp index 570938653..ab3274138 100644 --- a/tests/library/hierarchy-orientation-indicator-test.cpp +++ b/tests/library/hierarchy-orientation-indicator-test.cpp @@ -233,13 +233,12 @@ namespace test { } } ASSERT (0 == level); - if (1 >= path_.size()) - { // add first node at begin of tree visitation - path_.clear(); - path_.push_back(nextNode); - return 0; // by convention, here the root is an implicitly pre-existing context - } - throw error::Logic("corrupted test data tree or tree visitation floundered"); + + // nextNode not found as child (i.e. fork) within current tree path + // --> start new tree path at root + path_.clear(); + path_.push_back(nextNode); + return 0; // by convention, here the root is an implicitly pre-existing context } }; @@ -366,9 +365,6 @@ namespace test { TreeRebuilder reconstructed (depthFirst (AddressExposingIter(eachElm (testWood))) >>= exploreChildren); - //////////////////TODO: problem is in WrappedSequence. The operator*() returns a ref, but AddressExposingIter returns a value - //////////////////TODO: solution idea: use a specialisation for AddressexposingIter in "depthFirst" - cout << reconstructed.children_.size() << "=?=" << testWood.size(); CHECK (reconstructed.children_ == testWood); }