at.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/ext/std/array.hpp>
  5. #include <boost/hana/assert.hpp>
  6. #include <boost/hana/at.hpp>
  7. #include <laws/base.hpp> // for move_only
  8. #include <array>
  9. namespace hana = boost::hana;
  10. int main() {
  11. // Check non-const lvalue reference
  12. {
  13. std::array<int, 2> arr = {{999, 888}};
  14. int& i = hana::at_c<0>(arr);
  15. BOOST_HANA_RUNTIME_CHECK(i == 999);
  16. arr[0] = 333;
  17. BOOST_HANA_RUNTIME_CHECK(i == 333);
  18. i = 444;
  19. BOOST_HANA_RUNTIME_CHECK(arr[0] == 444);
  20. }
  21. // Check const lvalue reference
  22. {
  23. std::array<int, 2> arr = {{999, 888}};
  24. int const& i = hana::at_c<0>(static_cast<std::array<int, 2> const&>(arr));
  25. BOOST_HANA_RUNTIME_CHECK(i == 999);
  26. arr[0] = 333;
  27. BOOST_HANA_RUNTIME_CHECK(i == 333);
  28. }
  29. // Check move-only types
  30. {
  31. std::array<hana::test::move_only, 2> arr{};
  32. hana::test::move_only m = hana::at_c<0>(std::move(arr));
  33. (void)m;
  34. }
  35. }