From 9e50d5a1b8875361f63698ab642f8fe9d316155d Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Sat, 21 Jun 2014 06:37:53 -0700 Subject: [PATCH] test(util/lazy_list): add simple lazy_list example Signed-off-by: Leonardo de Moura --- src/tests/util/lazy_list.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tests/util/lazy_list.cpp b/src/tests/util/lazy_list.cpp index 4ddca2087..8ee167302 100644 --- a/src/tests/util/lazy_list.cpp +++ b/src/tests/util/lazy_list.cpp @@ -168,11 +168,33 @@ static void tst4() { list({ 1, 2, 2, 4, 2, 4, 4, 8, 2, 4, 4, 8, 4, 8, 8, 16 })); } +class gen { + unsigned m_next; +public: + gen():m_next(0) {} + unsigned next() { unsigned r = m_next; m_next++; return r; } +}; + +lazy_list mk_gen(std::shared_ptr const & g) { + return mk_lazy_list([=]() { return some(mk_pair(g->next(), mk_gen(g))); }); +} + +lazy_list mk_gen() { + return mk_gen(std::make_shared()); +} + +void tst5() { + auto l = mk_gen(); + display(take(10, l)); + display(take(10, l)); +} + int main() { save_stack_info(); tst1(); tst2(); tst3(); tst4(); + tst5(); return has_violations() ? 1 : 0; }