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