2
0
mirror of https://github.com/boostorg/hana.git synced 2026-01-26 06:32:18 +00:00
Files
hana/test/ext/std/array/at.cpp
Jason Rice ea571a11fc Fix Github Issue 304
- Apparently std::array operator[] returns an lvalue reference when unpacking
    a temporary std::array. Using std::get<n> returns the
    proper reference type in the case of rvalues.
  - Adds test by ldionne
2016-10-23 11:59:02 -07:00

44 lines
1.1 KiB
C++

// Copyright Louis Dionne 2013-2016
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#include <boost/hana/ext/std/array.hpp>
#include <boost/hana/assert.hpp>
#include <boost/hana/at.hpp>
#include <laws/base.hpp> // for move_only
#include <array>
namespace hana = boost::hana;
int main() {
// Check non-const lvalue reference
{
std::array<int, 2> arr = {{999, 888}};
int& i = hana::at_c<0>(arr);
BOOST_HANA_RUNTIME_CHECK(i == 999);
arr[0] = 333;
BOOST_HANA_RUNTIME_CHECK(i == 333);
i = 444;
BOOST_HANA_RUNTIME_CHECK(arr[0] == 444);
}
// Check const lvalue reference
{
std::array<int, 2> arr = {{999, 888}};
int const& i = hana::at_c<0>(static_cast<std::array<int, 2> const&>(arr));
BOOST_HANA_RUNTIME_CHECK(i == 999);
arr[0] = 333;
BOOST_HANA_RUNTIME_CHECK(i == 333);
}
// Check move-only types
{
std::array<hana::test::move_only, 2> arr{};
hana::test::move_only m = hana::at_c<0>(std::move(arr));
(void)m;
}
}