3 Defines `boost::hana::reverse`.
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_REVERSE_HPP
11 #define BOOST_HANA_REVERSE_HPP
13 #include <boost/hana/fwd/reverse.hpp>
15 #include <boost/hana/at.hpp>
16 #include <boost/hana/concept/sequence.hpp>
17 #include <boost/hana/config.hpp>
18 #include <boost/hana/core/dispatch.hpp>
19 #include <boost/hana/core/make.hpp>
20 #include <boost/hana/length.hpp>
26 BOOST_HANA_NAMESPACE_BEGIN
28 template <typename Xs>
29 constexpr auto reverse_t::operator()(Xs&& xs) const {
30 using S = typename hana::tag_of<Xs>::type;
31 using Reverse = BOOST_HANA_DISPATCH_IF(reverse_impl<S>,
32 hana::Sequence<S>::value
35 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
36 static_assert(hana::Sequence<S>::value,
37 "hana::reverse(xs) requires 'xs' to be a Sequence");
40 return Reverse::apply(static_cast<Xs&&>(xs));
44 template <typename S, bool condition>
45 struct reverse_impl<S, when<condition>> : default_ {
46 template <typename Xs, std::size_t ...i>
47 static constexpr auto reverse_helper(Xs&& xs, std::index_sequence<i...>) {
49 hana::at_c<sizeof...(i) - i - 1>(static_cast<Xs&&>(xs))...
53 template <typename Xs>
54 static constexpr auto apply(Xs&& xs) {
55 constexpr std::size_t N = decltype(hana::length(xs))::value;
56 return reverse_helper(static_cast<Xs&&>(xs), std::make_index_sequence<N>{});
59 BOOST_HANA_NAMESPACE_END
61 #endif // !BOOST_HANA_REVERSE_HPP