refactor(kernel/for_each_fn): simplify module interface

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-07-23 18:14:44 -07:00
parent 42867d6fcd
commit 61df118339
2 changed files with 69 additions and 68 deletions

View file

@ -8,7 +8,11 @@ Author: Leonardo de Moura
#include "kernel/for_each_fn.h"
namespace lean {
void for_each_fn::apply(expr const & e, unsigned offset) {
class for_each_fn {
std::unique_ptr<expr_cell_offset_set> m_visited;
std::function<bool(expr const &, unsigned)> m_f; // NOLINT
void apply(expr const & e, unsigned offset) {
buffer<std::pair<expr const &, unsigned>> todo;
todo.emplace_back(e, offset);
while (true) {
@ -66,5 +70,15 @@ void for_each_fn::apply(expr const & e, unsigned offset) {
goto begin_loop;
}
}
}
public:
for_each_fn(std::function<bool(expr const &, unsigned)> && f):m_f(f) {} // NOLINT
for_each_fn(std::function<bool(expr const &, unsigned)> const & f):m_f(f) {} // NOLINT
void operator()(expr const & e) { apply(e, 0); }
};
void for_each(expr const & e, std::function<bool(expr const &, unsigned)> && f) { // NOLINT
return for_each_fn(f)(e);
}
}

View file

@ -13,10 +13,9 @@ Author: Leonardo de Moura
#include "kernel/expr_sets.h"
namespace lean {
/**
\brief Expression visitor.
/** \brief Expression visitor.
The argument \c F must be a lambda (function object) containing the method
The argument \c f must be a lambda (function object) containing the method
<code>
bool operator()(expr const & e, unsigned offset)
@ -24,17 +23,5 @@ namespace lean {
The \c offset is the number of binders under which \c e occurs.
*/
class for_each_fn {
std::unique_ptr<expr_cell_offset_set> m_visited;
std::function<bool(expr const &, unsigned)> m_f; // NOLINT
void apply(expr const & e, unsigned offset);
public:
template<typename F> for_each_fn(F && f):m_f(f) {}
template<typename F> for_each_fn(F const & f):m_f(f) {}
void operator()(expr const & e) { apply(e, 0); }
};
template<typename F> void for_each(expr const & e, F && f) {
return for_each_fn(f)(e);
}
void for_each(expr const & e, std::function<bool(expr const &, unsigned)> && f); // NOLINT
}