memgraph/include/utils/iterator/for_all.hpp

42 lines
683 B
C++
Raw Normal View History

#pragma once
2016-08-28 22:47:13 +08:00
#include <memory>
#include "utils/option.hpp"
namespace iter
{
template <class I, class C>
void for_all(I &&iter, C &&consumer)
{
auto e = iter.next();
while (e.is_present()) {
consumer(e.take());
e = iter.next();
}
}
template <class I, class C>
void for_all(std::unique_ptr<I> &&iter, C &&consumer)
{
auto e = iter->next();
while (e.is_present()) {
consumer(e.take());
e = iter->next();
}
}
2016-08-30 09:32:31 +08:00
template <class I, class C>
void find(I iter, C &&consumer)
{
auto e = iter.next();
while (e.is_present()) {
if (consumer(e.take())) {
return;
}
e = iter.next();
}
}
}