File indexing completed on 2025-01-18 09:38:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_REVERSE_HPP
0011 #define BOOST_HANA_REVERSE_HPP
0012
0013 #include <boost/hana/fwd/reverse.hpp>
0014
0015 #include <boost/hana/at.hpp>
0016 #include <boost/hana/concept/sequence.hpp>
0017 #include <boost/hana/config.hpp>
0018 #include <boost/hana/core/dispatch.hpp>
0019 #include <boost/hana/core/make.hpp>
0020 #include <boost/hana/length.hpp>
0021
0022 #include <cstddef>
0023 #include <utility>
0024
0025
0026 namespace boost { namespace hana {
0027
0028 template <typename Xs>
0029 constexpr auto reverse_t::operator()(Xs&& xs) const {
0030 using S = typename hana::tag_of<Xs>::type;
0031 using Reverse = BOOST_HANA_DISPATCH_IF(reverse_impl<S>,
0032 hana::Sequence<S>::value
0033 );
0034
0035 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0036 static_assert(hana::Sequence<S>::value,
0037 "hana::reverse(xs) requires 'xs' to be a Sequence");
0038 #endif
0039
0040 return Reverse::apply(static_cast<Xs&&>(xs));
0041 }
0042
0043
0044 template <typename S, bool condition>
0045 struct reverse_impl<S, when<condition>> : default_ {
0046 template <typename Xs, std::size_t ...i>
0047 static constexpr auto reverse_helper(Xs&& xs, std::index_sequence<i...>) {
0048 return hana::make<S>(
0049 hana::at_c<sizeof...(i) - i - 1>(static_cast<Xs&&>(xs))...
0050 );
0051 }
0052
0053 template <typename Xs>
0054 static constexpr auto apply(Xs&& xs) {
0055 constexpr std::size_t N = decltype(hana::length(xs))::value;
0056 return reverse_helper(static_cast<Xs&&>(xs), std::make_index_sequence<N>{});
0057 }
0058 };
0059 }}
0060
0061 #endif