20 #ifndef TULIP_STLITERATOR_H 21 #define TULIP_STLITERATOR_H 24 #include <type_traits> 26 #include <tulip/Iterator.h> 27 #include <tulip/memorypool.h> 43 template <
typename T,
typename ITERATOR>
45 StlIterator(
const ITERATOR &startIt,
const ITERATOR &endIt) : it(startIt), itEnd(endIt) {}
59 template <
typename T,
typename ITERATOR>
60 struct MPStlIterator :
public StlIterator<T, ITERATOR>,
61 public MemoryPool<MPStlIterator<T, ITERATOR>> {
62 MPStlIterator(
const ITERATOR &startIt,
const ITERATOR &endIt)
69 struct has_const_iterator {
72 static char test(
typename C::const_iterator *);
77 enum { value =
sizeof(test<T>(0)) ==
sizeof(char) };
91 template <
typename Container>
92 typename std::enable_if<
93 has_const_iterator<Container>::value,
96 return new MPStlIterator<typename Container::value_type, typename Container::const_iterator>(
97 stlContainer.begin(), stlContainer.end());
101 template <
typename KEY,
typename VALUE>
102 struct StlMapIterator :
public Iterator<std::pair<KEY, VALUE>> {
103 StlMapIterator(
typename std::map<KEY, VALUE>::const_iterator startIt,
104 typename std::map<KEY, VALUE>::const_iterator endIt)
105 : it(startIt), itEnd(endIt) {}
107 std::pair<KEY, VALUE>
next() {
108 std::pair<KEY, VALUE> tmp = *it;
114 return (itEnd != it);
118 typename std::map<KEY, VALUE>::const_iterator it, itEnd;
121 template <
typename KEY,
typename VALUE>
123 StlMapKeyIterator(
typename std::map<KEY, VALUE>::const_iterator startIt,
124 typename std::map<KEY, VALUE>::const_iterator endIt)
125 : it(startIt), itEnd(endIt) {}
128 const KEY tmp = it->first;
138 typename std::map<KEY, VALUE>::const_iterator it, itEnd;
Interface for Tulip iterators. Allows basic iteration operations only.
StlIterator wraps a stl iterator.
T next()
Moves the Iterator on the next element.
std::enable_if< has_const_iterator< Container >::value, StlIterator< typename Container::value_type, typename Container::const_iterator > * >::type stlIterator(const Container &stlContainer)
Convenient function for creating a StlIterator from a stl container.
bool hasNext()
Tells if the sequence is at its end.