File indexing completed on 2025-01-18 09:38:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_INSERT_RANGE_HPP
0011 #define BOOST_HANA_INSERT_RANGE_HPP
0012
0013 #include <boost/hana/fwd/insert_range.hpp>
0014
0015 #include <boost/hana/concat.hpp>
0016 #include <boost/hana/concept/foldable.hpp>
0017 #include <boost/hana/concept/sequence.hpp>
0018 #include <boost/hana/config.hpp>
0019 #include <boost/hana/core/to.hpp>
0020 #include <boost/hana/core/dispatch.hpp>
0021 #include <boost/hana/drop_front.hpp>
0022 #include <boost/hana/take_front.hpp>
0023
0024
0025 namespace boost { namespace hana {
0026
0027 template <typename Xs, typename N, typename Elements>
0028 constexpr auto insert_range_t::operator()(Xs&& xs, N&& n, Elements&& elements) const {
0029 using S = typename hana::tag_of<Xs>::type;
0030 using InsertRange = BOOST_HANA_DISPATCH_IF(insert_range_impl<S>,
0031 hana::Sequence<Xs>::value &&
0032 hana::Foldable<Elements>::value
0033 );
0034
0035 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0036 static_assert(hana::Sequence<Xs>::value,
0037 "hana::insert_range(xs, n, elements) requires 'xs' to be a Sequence");
0038
0039 static_assert(hana::Foldable<Elements>::value,
0040 "hana::insert_range(xs, n, elements) requires 'elements' to be a Foldable");
0041 #endif
0042
0043 return InsertRange::apply(static_cast<Xs&&>(xs),
0044 static_cast<N&&>(n),
0045 static_cast<Elements&&>(elements));
0046 }
0047
0048
0049 template <typename S, bool condition>
0050 struct insert_range_impl<S, when<condition>> {
0051 template <typename Xs, typename N, typename Elements>
0052 static constexpr auto apply(Xs&& xs, N const& n, Elements&& e) {
0053 return hana::concat(
0054 hana::concat(
0055 hana::take_front(xs, n),
0056 hana::to<S>(static_cast<Elements&&>(e))
0057 ),
0058 hana::drop_front(xs, n)
0059 );
0060 }
0061 };
0062 }}
0063
0064 #endif