foldable.cpp 669 B

123456789101112131415161718192021222324252627
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/assert.hpp>
  5. #include <boost/hana/fold_left.hpp>
  6. #include <boost/hana/tuple.hpp>
  7. #include <sstream>
  8. namespace hana = boost::hana;
  9. auto to_string = [](auto x) {
  10. std::ostringstream ss;
  11. ss << x;
  12. return ss.str();
  13. };
  14. auto show = [](auto x, auto y) {
  15. return "(" + to_string(x) + " + " + to_string(y) + ")";
  16. };
  17. int main() {
  18. BOOST_HANA_RUNTIME_CHECK(
  19. hana::fold_left(hana::make_tuple(2, "3", '4'), "1", show) == "(((1 + 2) + 3) + 4)"
  20. );
  21. }