File indexing completed on 2025-01-18 09:38:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_REMOVE_RANGE_HPP
0011 #define BOOST_HANA_REMOVE_RANGE_HPP
0012
0013 #include <boost/hana/fwd/remove_range.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 From, typename To>
0031 constexpr auto remove_range_t::operator()(Xs&& xs, From const& from, To const& to) const {
0032 using S = typename hana::tag_of<Xs>::type;
0033 using RemoveRange = BOOST_HANA_DISPATCH_IF(remove_range_impl<S>,
0034 hana::Sequence<S>::value &&
0035 hana::IntegralConstant<From>::value &&
0036 hana::IntegralConstant<To>::value
0037 );
0038
0039 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0040 static_assert(hana::Sequence<S>::value,
0041 "hana::remove_range(xs, from, to) requires 'xs' to be a Sequence");
0042
0043 static_assert(hana::IntegralConstant<From>::value,
0044 "hana::remove_range(xs, from, to) requires 'from' to be an IntegralConstant");
0045
0046 static_assert(hana::IntegralConstant<To>::value,
0047 "hana::remove_range(xs, from, to) requires 'to' to be an IntegralConstant");
0048 #endif
0049
0050 return RemoveRange::apply(static_cast<Xs&&>(xs), from, to);
0051 }
0052
0053
0054 template <typename S, bool condition>
0055 struct remove_range_impl<S, when<condition>> : default_ {
0056 template <std::size_t offset, typename Xs, std::size_t ...before, std::size_t ...after>
0057 static constexpr auto
0058 remove_range_helper(Xs&& xs, std::index_sequence<before...>,
0059 std::index_sequence<after...>)
0060 {
0061 return hana::make<S>(
0062 hana::at_c<before>(static_cast<Xs&&>(xs))...,
0063 hana::at_c<offset + after>(static_cast<Xs&&>(xs))...
0064 );
0065 }
0066
0067 template <typename Xs, typename From, typename To>
0068 static constexpr auto apply(Xs&& xs, From const&, To const&) {
0069 constexpr std::size_t from = From::value;
0070 constexpr std::size_t to = To::value;
0071 constexpr std::size_t len = decltype(hana::length(xs))::value;
0072 constexpr std::size_t before = from == to ? len : from;
0073 constexpr std::size_t after = from == to ? 0 : len - to;
0074
0075 static_assert(from <= to,
0076 "hana::remove_range(xs, from, to) requires '[from, to)' to be a "
0077 "valid interval, meaning that 'from <= to'");
0078 static_assert(from == to || from >= 0,
0079 "hana::remove_range(xs, from, to) requires 'from' to be non-negative");
0080 static_assert(from == to || to <= len,
0081 "hana::remove_range(xs, from, to) requires 'to <= length(xs)'");
0082
0083 return remove_range_helper<to>(static_cast<Xs&&>(xs),
0084 std::make_index_sequence<before>{},
0085 std::make_index_sequence<after>{});
0086 }
0087 };
0088
0089 template <std::size_t from, std::size_t to>
0090 struct remove_range_c_t {
0091 template <typename Xs>
0092 constexpr decltype(auto) operator()(Xs&& xs) const {
0093 return hana::remove_range(static_cast<Xs&&>(xs),
0094 hana::size_c<from>,
0095 hana::size_c<to>);
0096 }
0097 };
0098 }}
0099
0100 #endif