]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/hana/insert_range.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / hana / insert_range.hpp
1 /*!
2 @file
3 Defines `boost::hana::insert_range`.
4
5 @copyright Louis Dionne 2013-2017
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_INSERT_RANGE_HPP
11 #define BOOST_HANA_INSERT_RANGE_HPP
12
13 #include <boost/hana/fwd/insert_range.hpp>
14
15 #include <boost/hana/concat.hpp>
16 #include <boost/hana/concept/foldable.hpp>
17 #include <boost/hana/concept/sequence.hpp>
18 #include <boost/hana/config.hpp>
19 #include <boost/hana/core/to.hpp>
20 #include <boost/hana/core/dispatch.hpp>
21 #include <boost/hana/drop_front.hpp>
22 #include <boost/hana/take_front.hpp>
23
24
25 namespace boost { namespace hana {
26 //! @cond
27 template <typename Xs, typename N, typename Elements>
28 constexpr auto insert_range_t::operator()(Xs&& xs, N&& n, Elements&& elements) const {
29 using S = typename hana::tag_of<Xs>::type;
30 using InsertRange = BOOST_HANA_DISPATCH_IF(insert_range_impl<S>,
31 hana::Sequence<Xs>::value &&
32 hana::Foldable<Elements>::value
33 );
34
35 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
36 static_assert(hana::Sequence<Xs>::value,
37 "hana::insert_range(xs, n, elements) requires 'xs' to be a Sequence");
38
39 static_assert(hana::Foldable<Elements>::value,
40 "hana::insert_range(xs, n, elements) requires 'elements' to be a Foldable");
41 #endif
42
43 return InsertRange::apply(static_cast<Xs&&>(xs),
44 static_cast<N&&>(n),
45 static_cast<Elements&&>(elements));
46 }
47 //! @endcond
48
49 template <typename S, bool condition>
50 struct insert_range_impl<S, when<condition>> {
51 template <typename Xs, typename N, typename Elements>
52 static constexpr auto apply(Xs&& xs, N const& n, Elements&& e) {
53 return hana::concat(
54 hana::concat(
55 hana::take_front(xs, n),
56 hana::to<S>(static_cast<Elements&&>(e))
57 ),
58 hana::drop_front(xs, n)
59 );
60 }
61 };
62 }} // end namespace boost::hana
63
64 #endif // !BOOST_HANA_INSERT_RANGE_HPP