// 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 #include #include #include #include #include #include #include #include #include namespace hana = boost::hana; // A tuple that holds reference_wrappers to its elements, instead of the // elements themselves. struct RefTuple { }; template struct ref_tuple; template struct ref_tuple { hana::tuple...> storage_; }; namespace boost { namespace hana { template struct tag_of> { using type = RefTuple; }; template <> struct make_impl { template static constexpr auto apply(T& ...t) { return ref_tuple{{std::ref(t)...}}; } }; template <> struct at_impl { template static constexpr decltype(auto) apply(Xs&& xs, N const& n) { return hana::at(static_cast(xs).storage_, n).get(); } }; template <> struct is_empty_impl { template static constexpr auto apply(Xs const& xs) { return hana::is_empty(xs.storage_); } }; template <> struct drop_front_impl { template static constexpr auto helper(ref_tuple xs, std::index_sequence) { return hana::make(hana::at_c(xs.storage_).get()...); } template static constexpr auto apply(ref_tuple xs, N const&) { return helper(xs, std::make_index_sequence<( N::value < sizeof...(T) ? sizeof...(T) - N::value : 0 )>{}); } }; }} // end namespace boost::hana int main() { int i = 0, j = 1, k = 2; ref_tuple refs = hana::make(i, j, k); hana::at_c<0>(refs) = 3; BOOST_HANA_RUNTIME_CHECK(i == 3); BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(refs))); ref_tuple tail = hana::drop_front(refs); hana::at_c<0>(tail) = 4; BOOST_HANA_RUNTIME_CHECK(j == 4); }