Skip to content

Commit

Permalink
removed persistent iterator to get rid of mysterious warning
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-hauns authored and quickbeam123 committed Aug 19, 2024
1 parent 44b72ec commit e77b9e5
Showing 1 changed file with 14 additions and 61 deletions.
75 changes: 14 additions & 61 deletions Lib/Metaiterators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,67 +626,6 @@ FlatMapIter<Inner,Functor> getMapAndFlattenIterator(Inner it, Functor f)
MappingIterator<Inner,Functor>(std::move(it), f) );
}

/**
* Iterator that in its constructor stores elements of an inner iterator
* and then returns these elements later in the same order
*
* The iterator object does not contain the copy constructor or
* the operator=. If this behavior is required, it should be created
* on the heap and pointer to it put inside a VirtualIterator object.
*
* This iterator should be used when a resource held by an iterator
* needs to be released before the elements of the iterator are required.
*
* @see VirtualIterator
*/
template<class Inner>
class PersistentIterator
: public IteratorCore<ELEMENT_TYPE(Inner)>
{
public:
typedef ELEMENT_TYPE(Inner) T;
explicit PersistentIterator(Inner inn)
: _items(0)
{
List<T>** ptr=&_items;
while(inn.hasNext()) {
*ptr=new List<T>(inn.next());
ptr=&(*ptr)->tailReference();
}
}
~PersistentIterator()
{
if(_items) {
List<T>::destroy(_items);
}
}
inline bool hasNext() { return _items; };
inline
T next()
{
return List<T>::pop(_items);
};
private:
List<T>* _items;
};

/**
* Return iterator that stores values of @b it in its constructor,
* and then yields them in the same order
*
* After the call to this function, the iterator @b it and any resources
* it holds may be released, since the elements are stored independently
* of it.
*
* @see PersistentIterator
*/
template<class Inner>
inline
VirtualIterator<ELEMENT_TYPE(Inner)> getPersistentIterator(Inner it)
{
return vi( new PersistentIterator<Inner>(it) );
}


/**
* Iterator that in its constructor stores elements of an inner iterator
Expand Down Expand Up @@ -1751,4 +1690,18 @@ STLIterator<Iterator> getSTLIterator(Iterator begin, Iterator end)
return STLIterator<Iterator>(begin, end);
}

/**
* Return iterator that stores values of @b it in its constructor,
* and then yields them in the same order
*
* After the call to this function, the iterator @b it and any resources
* it holds may be released, since the elements are stored independently
* of it.
*
* @see PersistentIterator
*/
template<class Inner>
auto getPersistentIterator(Inner it)
{ return pvi(arrayIter(iterTraits(it).template collect<Stack>())); }

#endif /* __Metaiterators__ */

0 comments on commit e77b9e5

Please sign in to comment.