]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/include/boost/hana/remove_range.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / remove_range.hpp
1 /*!
2 @file
3 Defines `boost::hana::remove_range` and `boost::hana::remove_range_c`.
4
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)
8 */
9
10 #ifndef BOOST_HANA_REMOVE_RANGE_HPP
11 #define BOOST_HANA_REMOVE_RANGE_HPP
12
13 #include <boost/hana/fwd/remove_range.hpp>
14
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>
23
24 #include <cstddef>
25 #include <utility>
26
27
28 BOOST_HANA_NAMESPACE_BEGIN
29 //! @cond
30 template <typename Xs, typename From, typename To>
31 constexpr auto remove_range_t::operator()(Xs&& xs, From const& from, To const& to) const {
32 using S = typename hana::tag_of<Xs>::type;
33 using RemoveRange = BOOST_HANA_DISPATCH_IF(remove_range_impl<S>,
34 hana::Sequence<S>::value &&
35 hana::IntegralConstant<From>::value &&
36 hana::IntegralConstant<To>::value
37 );
38
39 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
40 static_assert(hana::Sequence<S>::value,
41 "hana::remove_range(xs, from, to) requires 'xs' to be a Sequence");
42
43 static_assert(hana::IntegralConstant<From>::value,
44 "hana::remove_range(xs, from, to) requires 'from' to be an IntegralConstant");
45
46 static_assert(hana::IntegralConstant<To>::value,
47 "hana::remove_range(xs, from, to) requires 'to' to be an IntegralConstant");
48 #endif
49
50 return RemoveRange::apply(static_cast<Xs&&>(xs), from, to);
51 }
52 //! @endcond
53
54 template <typename S, bool condition>
55 struct remove_range_impl<S, when<condition>> : default_ {
56 template <std::size_t offset, typename Xs, std::size_t ...before, std::size_t ...after>
57 static constexpr auto
58 remove_range_helper(Xs&& xs, std::index_sequence<before...>,
59 std::index_sequence<after...>)
60 {
61 return hana::make<S>(
62 hana::at_c<before>(static_cast<Xs&&>(xs))...,
63 hana::at_c<offset + after>(static_cast<Xs&&>(xs))...
64 );
65 }
66
67 template <typename Xs, typename From, typename To>
68 static constexpr auto apply(Xs&& xs, From const&, To const&) {
69 constexpr std::size_t from = From::value;
70 constexpr std::size_t to = To::value;
71 constexpr std::size_t len = decltype(hana::length(xs))::value;
72 constexpr std::size_t before = from == to ? len : from;
73 constexpr std::size_t after = from == to ? 0 : len - to;
74
75 static_assert(from <= to,
76 "hana::remove_range(xs, from, to) requires '[from, to)' to be a "
77 "valid interval, meaning that 'from <= to'");
78 static_assert(from == to || from >= 0,
79 "hana::remove_range(xs, from, to) requires 'from' to be non-negative");
80 static_assert(from == to || to <= len,
81 "hana::remove_range(xs, from, to) requires 'to <= length(xs)'");
82
83 return remove_range_helper<to>(static_cast<Xs&&>(xs),
84 std::make_index_sequence<before>{},
85 std::make_index_sequence<after>{});
86 }
87 };
88
89 template <std::size_t from, std::size_t to>
90 struct remove_range_c_t {
91 template <typename Xs>
92 constexpr decltype(auto) operator()(Xs&& xs) const {
93 return hana::remove_range(static_cast<Xs&&>(xs),
94 hana::size_c<from>,
95 hana::size_c<to>);
96 }
97 };
98 BOOST_HANA_NAMESPACE_END
99
100 #endif // !BOOST_HANA_REMOVE_RANGE_HPP