ref.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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/at.hpp>
  6. #include <boost/hana/fold_left.hpp>
  7. #include <boost/hana/tuple.hpp>
  8. namespace hana = boost::hana;
  9. //
  10. // Make sure that we can fold_left and take arguments by reference.
  11. //
  12. int main() {
  13. // with state
  14. {
  15. auto xs = hana::make_tuple(1, 2, 3);
  16. int state = 99;
  17. int& three = hana::fold_left(xs, state, [](int&, int& i) -> int& {
  18. return i;
  19. });
  20. BOOST_HANA_RUNTIME_CHECK(three == 3);
  21. three = 10;
  22. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(xs) == 10);
  23. }
  24. // without state
  25. {
  26. auto xs = hana::make_tuple(1, 2, 3);
  27. int& three = hana::fold_left(xs, [](int&, int& i) -> int& {
  28. return i;
  29. });
  30. BOOST_HANA_RUNTIME_CHECK(three == 3);
  31. three = 10;
  32. BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(xs) == 10);
  33. }
  34. }