File indexing completed on 2025-01-18 09:38:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_REMOVE_AT_HPP
0011 #define BOOST_HANA_REMOVE_AT_HPP
0012
0013 #include <boost/hana/fwd/remove_at.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 remove_at_t::operator()(Xs&& xs, N const& n) const {
0032 using S = typename hana::tag_of<Xs>::type;
0033 using RemoveAt = BOOST_HANA_DISPATCH_IF(remove_at_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::remove_at(xs, n) requires 'xs' to be a Sequence");
0041
0042 static_assert(hana::IntegralConstant<N>::value,
0043 "hana::remove_at(xs, n) requires 'n' to be an IntegralConstant");
0044 #endif
0045
0046 static_assert(N::value >= 0,
0047 "hana::remove_at(xs, n) requires 'n' to be non-negative");
0048
0049 return RemoveAt::apply(static_cast<Xs&&>(xs), n);
0050 }
0051
0052
0053 template <typename S, bool condition>
0054 struct remove_at_impl<S, when<condition>> : default_ {
0055 template <typename Xs, std::size_t ...before, std::size_t ...after>
0056 static constexpr auto
0057 remove_at_helper(Xs&& xs, std::index_sequence<before...>,
0058 std::index_sequence<after...>)
0059 {
0060 return hana::make<S>(
0061 hana::at_c<before>(static_cast<Xs&&>(xs))...,
0062 hana::at_c<after + sizeof...(before) + 1>(static_cast<Xs&&>(xs))...
0063 );
0064 }
0065
0066 template <typename Xs, typename N>
0067 static constexpr auto apply(Xs&& xs, N const&) {
0068 constexpr std::size_t n = N::value;
0069 constexpr std::size_t len = decltype(hana::length(xs))::value;
0070 static_assert(n < len,
0071 "hana::remove_at(xs, n) requires 'n' to be in the bounds of the sequence");
0072 return remove_at_helper(static_cast<Xs&&>(xs),
0073 std::make_index_sequence<n>{},
0074 std::make_index_sequence<len - n - 1>{});
0075 }
0076 };
0077
0078 template <std::size_t n>
0079 struct remove_at_c_t {
0080 template <typename Xs>
0081 constexpr decltype(auto) operator()(Xs&& xs) const
0082 { return hana::remove_at(static_cast<Xs&&>(xs), hana::size_c<n>); }
0083 };
0084 }}
0085
0086 #endif