]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/include/boost/hana/remove_at.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / hana / include / boost / hana / remove_at.hpp
CommitLineData
7c673cae
FG
1/*!
2@file
3Defines `boost::hana::remove_at` and `boost::hana::remove_at_c`.
4
5@copyright Louis Dionne 2013-2016
6Distributed 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_AT_HPP
11#define BOOST_HANA_REMOVE_AT_HPP
12
13#include <boost/hana/fwd/remove_at.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
28BOOST_HANA_NAMESPACE_BEGIN
29 //! @cond
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
36 );
37
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");
41
42 static_assert(hana::IntegralConstant<N>::value,
43 "hana::remove_at(xs, n) requires 'n' to be an IntegralConstant");
44 #endif
45
46 static_assert(N::value >= 0,
47 "hana::remove_at(xs, n) requires 'n' to be non-negative");
48
49 return RemoveAt::apply(static_cast<Xs&&>(xs), n);
50 }
51 //! @endcond
52
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>
56 static constexpr auto
57 remove_at_helper(Xs&& xs, std::index_sequence<before...>,
58 std::index_sequence<after...>)
59 {
60 return hana::make<S>(
61 hana::at_c<before>(static_cast<Xs&&>(xs))...,
62 hana::at_c<after + sizeof...(before) + 1>(static_cast<Xs&&>(xs))...
63 );
64 }
65
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>{});
75 }
76 };
77
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>); }
83 };
84BOOST_HANA_NAMESPACE_END
85
86#endif // !BOOST_HANA_REMOVE_AT_HPP