at.rv.cpp 1.2 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/tuple.hpp>
  6. #include <support/tracked.hpp>
  7. #include <utility>
  8. #include <memory>
  9. namespace hana = boost::hana;
  10. int main() {
  11. {
  12. using T = hana::tuple<std::unique_ptr<int>>;
  13. T t(std::unique_ptr<int>(new int(3)));
  14. std::unique_ptr<int> p = hana::at_c<0>(std::move(t));
  15. BOOST_HANA_RUNTIME_CHECK(*p == 3);
  16. }
  17. // make sure we don't double-move and do other weird stuff
  18. {
  19. hana::tuple<Tracked, Tracked, Tracked> xs{
  20. Tracked{1}, Tracked{2}, Tracked{3}
  21. };
  22. Tracked a = hana::at_c<0>(std::move(xs)); (void)a;
  23. Tracked b = hana::at_c<1>(std::move(xs)); (void)b;
  24. Tracked c = hana::at_c<2>(std::move(xs)); (void)c;
  25. }
  26. // test with nested closures
  27. {
  28. using Inner = hana::tuple<Tracked, Tracked>;
  29. hana::tuple<Inner> xs{Inner{Tracked{1}, Tracked{2}}};
  30. Tracked a = hana::at_c<0>(hana::at_c<0>(std::move(xs))); (void)a;
  31. Tracked b = hana::at_c<1>(hana::at_c<0>(std::move(xs))); (void)b;
  32. }
  33. }