diff options
Diffstat (limited to 'src/boost/libs/hana/test/issues/github_365.cpp')
-rw-r--r-- | src/boost/libs/hana/test/issues/github_365.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/boost/libs/hana/test/issues/github_365.cpp b/src/boost/libs/hana/test/issues/github_365.cpp new file mode 100644 index 00000000..63d756f4 --- /dev/null +++ b/src/boost/libs/hana/test/issues/github_365.cpp @@ -0,0 +1,61 @@ +// Copyright Louis Dionne 2013-2017 +// 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/accessors.hpp> +#include <boost/hana/adapt_struct.hpp> +#include <boost/hana/assert.hpp> +#include <boost/hana/at.hpp> +#include <boost/hana/define_struct.hpp> +#include <boost/hana/second.hpp> + +#include <cstddef> +#include <type_traits> +namespace hana = boost::hana; + + +// +// This test makes sure that `hana::accessors` does not decay C-style array +// members to pointers. +// + +struct Foo { + float array[3]; +}; + +BOOST_HANA_ADAPT_STRUCT(Foo, + array +); + +template <std::size_t N> +using FloatArray = float[N]; + +struct Bar { + BOOST_HANA_DEFINE_STRUCT(Bar, + (FloatArray<3>, array) + ); +}; + +int main() { + { + Foo foo = {{1.0f, 2.0f, 3.0f}}; + auto accessors = hana::accessors<Foo>(); + auto get_array = hana::second(hana::at_c<0>(accessors)); + static_assert(std::is_same<decltype(get_array(foo)), float(&)[3]>{}, ""); + float (&array)[3] = get_array(foo); + BOOST_HANA_RUNTIME_CHECK(array[0] == 1.0f); + BOOST_HANA_RUNTIME_CHECK(array[1] == 2.0f); + BOOST_HANA_RUNTIME_CHECK(array[2] == 3.0f); + } + + { + Bar bar = {{1.0f, 2.0f, 3.0f}}; + auto accessors = hana::accessors<Bar>(); + auto get_array = hana::second(hana::at_c<0>(accessors)); + static_assert(std::is_same<decltype(get_array(bar)), float(&)[3]>{}, ""); + float (&array)[3] = get_array(bar); + BOOST_HANA_RUNTIME_CHECK(array[0] == 1.0f); + BOOST_HANA_RUNTIME_CHECK(array[1] == 2.0f); + BOOST_HANA_RUNTIME_CHECK(array[2] == 3.0f); + } +} |