3 Defines `boost::hana::remove_at` and `boost::hana::remove_at_c`.
5 @copyright Louis Dionne 2013-2016
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_REMOVE_AT_HPP
11 #define BOOST_HANA_REMOVE_AT_HPP
13 #include <boost/hana/fwd/remove_at.hpp>
15 #include <boost/hana/at.hpp>
16 #include <boost/hana/concept/integral_constant.hpp>
17 #include <boost/hana/concept/sequence.hpp>
18 #include <boost/hana/config.hpp>
19 #include <boost/hana/core/dispatch.hpp>
20 #include <boost/hana/core/make.hpp>
21 #include <boost/hana/integral_constant.hpp>
22 #include <boost/hana/length.hpp>
28 BOOST_HANA_NAMESPACE_BEGIN
30 template <typename Xs, typename N>
31 constexpr auto remove_at_t::operator()(Xs&& xs, N const& n) const {
32 using S = typename hana::tag_of<Xs>::type;
33 using RemoveAt = BOOST_HANA_DISPATCH_IF(remove_at_impl<S>,
34 hana::Sequence<S>::value &&
35 hana::IntegralConstant<N>::value
38 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
39 static_assert(hana::Sequence<S>::value,
40 "hana::remove_at(xs, n) requires 'xs' to be a Sequence");
42 static_assert(hana::IntegralConstant<N>::value,
43 "hana::remove_at(xs, n) requires 'n' to be an IntegralConstant");
46 static_assert(N::value >= 0,
47 "hana::remove_at(xs, n) requires 'n' to be non-negative");
49 return RemoveAt::apply(static_cast<Xs&&>(xs), n);
53 template <typename S, bool condition>
54 struct remove_at_impl<S, when<condition>> : default_ {
55 template <typename Xs, std::size_t ...before, std::size_t ...after>
57 remove_at_helper(Xs&& xs, std::index_sequence<before...>,
58 std::index_sequence<after...>)
61 hana::at_c<before>(static_cast<Xs&&>(xs))...,
62 hana::at_c<after + sizeof...(before) + 1>(static_cast<Xs&&>(xs))...
66 template <typename Xs, typename N>
67 static constexpr auto apply(Xs&& xs, N const&) {
68 constexpr std::size_t n = N::value;
69 constexpr std::size_t len = decltype(hana::length(xs))::value;
70 static_assert(n < len,
71 "hana::remove_at(xs, n) requires 'n' to be in the bounds of the sequence");
72 return remove_at_helper(static_cast<Xs&&>(xs),
73 std::make_index_sequence<n>{},
74 std::make_index_sequence<len - n - 1>{});
78 template <std::size_t n>
79 struct remove_at_c_t {
80 template <typename Xs>
81 constexpr decltype(auto) operator()(Xs&& xs) const
82 { return hana::remove_at(static_cast<Xs&&>(xs), hana::size_c<n>); }
84 BOOST_HANA_NAMESPACE_END
86 #endif // !BOOST_HANA_REMOVE_AT_HPP