ref.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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_right.hpp>
  7. #include <boost/hana/tuple.hpp>
  8. namespace hana = boost::hana;
  9. //
  10. // Make sure that we can fold_right 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& one = hana::fold_right(xs, state, [](int& i, int&) -> int& {
  18. return i;
  19. });
  20. BOOST_HANA_RUNTIME_CHECK(one == 1);
  21. one = 10;
  22. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(xs) == 10);
  23. }
  24. // without state
  25. {
  26. auto xs = hana::make_tuple(1, 2, 3);
  27. int& one = hana::fold_right(xs, [](int& i, int&) -> int& {
  28. return i;
  29. });
  30. BOOST_HANA_RUNTIME_CHECK(one == 1);
  31. one = 10;
  32. BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(xs) == 10);
  33. }
  34. }