2
0
mirror of https://github.com/boostorg/hana.git synced 2026-02-17 01:42:10 +00:00
Files
hana/example/list/foldable/lazy_foldr.cpp
2014-06-12 13:33:38 -04:00

31 lines
865 B
C++

/*
@copyright Louis Dionne 2014
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#include <boost/hana/functional.hpp>
#include <boost/hana/integral.hpp>
#include <boost/hana/logical.hpp>
#include <boost/hana/range.hpp>
#include <cassert>
#include <sstream>
using namespace boost::hana;
using namespace literals;
int main() {
//! [main]
auto to_string = [](auto x) { return (std::ostringstream{} << x).str(); };
auto show = [=](auto x, auto y) {
auto y_ = if_(x() < 4_c, y, always("..."))();
return "(" + to_string(x()) + " + " + to_string(y_) + ")";
};
auto state = [] { assert(false); }; // this will never be evaluated
assert(lazy_foldr(show, state, range(1_c, 999999_c)) == "(1 + (2 + (3 + (4 + ...))))");
//! [main]
}