/*! @file Defines `boost::hana::remove_range` and `boost::hana::remove_range_c`. @copyright Louis Dionne 2013-2017 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_REMOVE_RANGE_HPP #define BOOST_HANA_REMOVE_RANGE_HPP #include #include #include #include #include #include #include #include #include #include #include BOOST_HANA_NAMESPACE_BEGIN //! @cond template constexpr auto remove_range_t::operator()(Xs&& xs, From const& from, To const& to) const { using S = typename hana::tag_of::type; using RemoveRange = BOOST_HANA_DISPATCH_IF(remove_range_impl, hana::Sequence::value && hana::IntegralConstant::value && hana::IntegralConstant::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::Sequence::value, "hana::remove_range(xs, from, to) requires 'xs' to be a Sequence"); static_assert(hana::IntegralConstant::value, "hana::remove_range(xs, from, to) requires 'from' to be an IntegralConstant"); static_assert(hana::IntegralConstant::value, "hana::remove_range(xs, from, to) requires 'to' to be an IntegralConstant"); #endif return RemoveRange::apply(static_cast(xs), from, to); } //! @endcond template struct remove_range_impl> : default_ { template static constexpr auto remove_range_helper(Xs&& xs, std::index_sequence, std::index_sequence) { return hana::make( hana::at_c(static_cast(xs))..., hana::at_c(static_cast(xs))... ); } template static constexpr auto apply(Xs&& xs, From const&, To const&) { constexpr std::size_t from = From::value; constexpr std::size_t to = To::value; constexpr std::size_t len = decltype(hana::length(xs))::value; constexpr std::size_t before = from == to ? len : from; constexpr std::size_t after = from == to ? 0 : len - to; static_assert(from <= to, "hana::remove_range(xs, from, to) requires '[from, to)' to be a " "valid interval, meaning that 'from <= to'"); static_assert(from == to || from >= 0, "hana::remove_range(xs, from, to) requires 'from' to be non-negative"); static_assert(from == to || to <= len, "hana::remove_range(xs, from, to) requires 'to <= length(xs)'"); return remove_range_helper(static_cast(xs), std::make_index_sequence{}, std::make_index_sequence{}); } }; template struct remove_range_c_t { template constexpr decltype(auto) operator()(Xs&& xs) const { return hana::remove_range(static_cast(xs), hana::size_c, hana::size_c); } }; BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_REMOVE_RANGE_HPP