/* @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 #include #include #include #include #include using namespace boost::hana; using namespace literals; int main() { //! [main] auto to_string = [](auto x) { return (std::ostringstream{} << x).str(); }; auto up_to = [=](auto n) { return [=](auto x, auto y) { auto y_ = if_(x() == n, always("..."), y)(); return "(" + to_string(x()) + " + " + to_string(y_) + ")"; }; }; constexpr struct { } state{}; // this will never be evaluated assert( lazy_foldr(up_to(4_c), state, range(1_c, 999999_c)) == "(1 + (2 + (3 + (4 + ...))))" ); //! [main] }