diff --git a/include/boost/hana/view.hpp b/include/boost/hana/view.hpp index bff5744f7f..735ce53077 100644 --- a/include/boost/hana/view.hpp +++ b/include/boost/hana/view.hpp @@ -349,7 +349,14 @@ BOOST_HANA_NAMESPACE_BEGIN // single_view template - static constexpr decltype(auto) apply(detail::single_view_t view, N const&) { + static constexpr T& apply(detail::single_view_t& view, N const&) { + static_assert(N::value == 0, + "trying to fetch an out-of-bounds element in a hana::single_view"); + return view.value_; + } + + template + static constexpr T const& apply(detail::single_view_t const& view, N const&) { static_assert(N::value == 0, "trying to fetch an out-of-bounds element in a hana::single_view"); return view.value_; diff --git a/test/view/flattened/modifications.cpp b/test/view/flattened/modifications.cpp new file mode 100644 index 0000000000..c3f2a30370 --- /dev/null +++ b/test/view/flattened/modifications.cpp @@ -0,0 +1,44 @@ +// 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 +#include +#include + +#include +namespace hana = boost::hana; + + +int main() { + auto container = ::seq; + + auto storage = container(container(0, 1, 2), + container(3, 4), + container(), + container(5)); + auto view = hana::detail::flattened(storage); + hana::at_c<0>(view) = 90; + hana::at_c<1>(view) = 91; + hana::at_c<2>(view) = 92; + hana::at_c<3>(view) = 93; + hana::at_c<4>(view) = 94; + hana::at_c<5>(view) = 95; + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(view) == 90); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(view) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(view) == 92); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<3>(view) == 93); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<4>(view) == 94); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<5>(view) == 95); + + auto& storage1 = hana::at_c<0>(storage); + auto& storage2 = hana::at_c<1>(storage); + auto& storage4 = hana::at_c<3>(storage); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(storage1) == 90); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(storage1) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(storage1) == 92); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(storage2) == 93); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(storage2) == 94); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(storage4) == 95); +} diff --git a/test/view/identity/modifications.cpp b/test/view/identity/modifications.cpp new file mode 100644 index 0000000000..f9a99b248d --- /dev/null +++ b/test/view/identity/modifications.cpp @@ -0,0 +1,29 @@ +// 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 +#include +#include + +#include +namespace hana = boost::hana; + + +int main() { + auto container = ::seq; + + auto storage = container(0, 1, 2); + auto view = hana::detail::identity_view(storage); + hana::at_c<0>(view) = 90; + hana::at_c<1>(view) = 91; + hana::at_c<2>(view) = 92; + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(view) == 90); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(view) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(view) == 92); + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(storage) == 90); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(storage) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(storage) == 92); +} diff --git a/test/view/joined/modifications.cpp b/test/view/joined/modifications.cpp new file mode 100644 index 0000000000..61fea1fd1c --- /dev/null +++ b/test/view/joined/modifications.cpp @@ -0,0 +1,36 @@ +// 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 +#include +#include + +#include +namespace hana = boost::hana; + + +int main() { + auto container = ::seq; + + auto storage1 = container(0, 1, 2); + auto storage2 = container(3, 4); + auto view = hana::detail::joined(storage1, storage2); + hana::at_c<0>(view) = 90; + hana::at_c<1>(view) = 91; + hana::at_c<2>(view) = 92; + hana::at_c<3>(view) = 93; + hana::at_c<4>(view) = 94; + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(view) == 90); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(view) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(view) == 92); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<3>(view) == 93); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<4>(view) == 94); + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(storage1) == 90); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(storage1) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(storage1) == 92); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(storage2) == 93); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(storage2) == 94); +} diff --git a/test/view/single/modifications.cpp b/test/view/single/modifications.cpp new file mode 100644 index 0000000000..026b8e9900 --- /dev/null +++ b/test/view/single/modifications.cpp @@ -0,0 +1,16 @@ +// 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 +#include +#include +namespace hana = boost::hana; + + +int main() { + auto view = hana::detail::single_view(3); + hana::at_c<0>(view) = 93; + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(view) == 93); +} diff --git a/test/view/sliced/modifications.cpp b/test/view/sliced/modifications.cpp new file mode 100644 index 0000000000..880525935a --- /dev/null +++ b/test/view/sliced/modifications.cpp @@ -0,0 +1,62 @@ +// 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 +#include +#include +#include + +#include + +#include +namespace hana = boost::hana; + + +int main() { + auto container = ::seq; + + { + auto storage = container(0, 1, 2); + auto view = hana::detail::sliced(storage, hana::range_c); + hana::at_c<0>(view) = 90; + hana::at_c<1>(view) = 91; + hana::at_c<2>(view) = 92; + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(view) == 90); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(view) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(view) == 92); + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(storage) == 90); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(storage) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(storage) == 92); + } + + { + auto storage = container(0, 1, 2); + auto view = hana::detail::sliced(storage, hana::range_c); + hana::at_c<0>(view) = 90; + hana::at_c<1>(view) = 91; + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(view) == 90); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(view) == 91); + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(storage) == 90); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(storage) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(storage) == 02); + } + + { + auto storage = container(7, 1, 2); + auto view = hana::detail::sliced(storage, hana::range_c); + hana::at_c<0>(view) = 91; + hana::at_c<1>(view) = 92; + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(view) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(view) == 92); + + BOOST_HANA_RUNTIME_CHECK(hana::at_c<0>(storage) == 07); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<1>(storage) == 91); + BOOST_HANA_RUNTIME_CHECK(hana::at_c<2>(storage) == 92); + } +}