3 Defines `boost::hana::insert_range`.
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)
10 #ifndef BOOST_HANA_INSERT_RANGE_HPP
11 #define BOOST_HANA_INSERT_RANGE_HPP
13 #include <boost/hana/fwd/insert_range.hpp>
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>
25 namespace boost { namespace hana {
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
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");
39 static_assert(hana::Foldable<Elements>::value,
40 "hana::insert_range(xs, n, elements) requires 'elements' to be a Foldable");
43 return InsertRange::apply(static_cast<Xs&&>(xs),
45 static_cast<Elements&&>(elements));
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) {
55 hana::take_front(xs, n),
56 hana::to<S>(static_cast<Elements&&>(e))
58 hana::drop_front(xs, n)
62 }} // end namespace boost::hana
64 #endif // !BOOST_HANA_INSERT_RANGE_HPP