File indexing completed on 2025-01-18 09:38:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_DROP_BACK_HPP
0011 #define BOOST_HANA_DROP_BACK_HPP
0012
0013 #include <boost/hana/fwd/drop_back.hpp>
0014
0015 #include <boost/hana/at.hpp>
0016 #include <boost/hana/concept/integral_constant.hpp>
0017 #include <boost/hana/concept/sequence.hpp>
0018 #include <boost/hana/config.hpp>
0019 #include <boost/hana/core/dispatch.hpp>
0020 #include <boost/hana/core/make.hpp>
0021 #include <boost/hana/integral_constant.hpp>
0022 #include <boost/hana/length.hpp>
0023
0024 #include <cstddef>
0025 #include <utility>
0026
0027
0028 namespace boost { namespace hana {
0029
0030 template <typename Xs, typename N>
0031 constexpr auto drop_back_t::operator()(Xs&& xs, N const& n) const {
0032 using S = typename hana::tag_of<Xs>::type;
0033 using DropBack = BOOST_HANA_DISPATCH_IF(drop_back_impl<S>,
0034 hana::Sequence<S>::value &&
0035 hana::IntegralConstant<N>::value
0036 );
0037
0038 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0039 static_assert(hana::Sequence<S>::value,
0040 "hana::drop_back(xs, n) requires 'xs' to be a Sequence");
0041
0042 static_assert(hana::IntegralConstant<N>::value,
0043 "hana::drop_back(xs, n) requires 'n' to be an IntegralConstant");
0044 #endif
0045
0046 static_assert(N::value >= 0,
0047 "hana::drop_back(xs, n) requires 'n' to be non-negative");
0048
0049 return DropBack::apply(static_cast<Xs&&>(xs), n);
0050 }
0051
0052 template <typename Xs>
0053 constexpr auto drop_back_t::operator()(Xs&& xs) const {
0054 return (*this)(static_cast<Xs&&>(xs), hana::size_c<1>);
0055 }
0056
0057
0058 template <typename S, bool condition>
0059 struct drop_back_impl<S, when<condition>> : default_ {
0060 template <typename Xs, std::size_t ...n>
0061 static constexpr auto drop_back_helper(Xs&& xs, std::index_sequence<n...>) {
0062 return hana::make<S>(hana::at_c<n>(static_cast<Xs&&>(xs))...);
0063 }
0064
0065 template <typename Xs, typename N>
0066 static constexpr auto apply(Xs&& xs, N const&) {
0067 constexpr std::size_t n = N::value;
0068 constexpr std::size_t len = decltype(hana::length(xs))::value;
0069 return drop_back_helper(static_cast<Xs&&>(xs),
0070 std::make_index_sequence<(n > len ? 0 : len - n)>{});
0071 }
0072 };
0073 }}
0074
0075 #endif